From 86a2eb8c86eaf0bf0834006b04138e2be45f4ceb Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Wed, 26 Jan 2022 10:44:34 +1100 Subject: [PATCH] Use jst_server.Problem everywhere, make /_lib/post_request.jst use jst_server's new error handling to serve the JSON-encoded Problem instead of doing it itself --- _lib/Problem.jst | 23 ----- _lib/post_request.jst | 84 +++++-------------- api/account/change_details/get.json.jst | 8 +- api/account/change_details/get_draft.json.jst | 2 +- api/account/change_details/set.json.jst | 10 ++- api/account/change_details/set_draft.json.jst | 2 +- api/account/change_password.json.jst | 12 ++- api/account/password_reset.json.jst | 6 +- api/account/sign_in.json.jst | 9 +- api/account/sign_out.json.jst | 3 +- api/account/sign_up/create_account.json.jst | 10 +-- api/account/sign_up/get_draft.json.jst | 2 +- .../send_email_verification_link.json.jst | 8 +- api/account/sign_up/set_draft.json.jst | 2 +- api/account/sign_up/verify_email.json.jst | 12 +-- api/account/verify_password.json.jst | 10 +-- api/contact/get_draft.json.jst | 2 +- api/contact/send_enquiry.json.jst | 4 +- api/contact/set_draft.json.jst | 2 +- api/globals/get.json.jst | 14 +++- api/globals/set.json.jst | 14 +++- api/nodemailers/get.json.jst | 14 +++- api/nodemailers/set.json.jst | 14 +++- link.sh | 2 +- package.json | 1 + 25 files changed, 128 insertions(+), 142 deletions(-) delete mode 100644 _lib/Problem.jst diff --git a/_lib/Problem.jst b/_lib/Problem.jst deleted file mode 100644 index 3b017c2..0000000 --- a/_lib/Problem.jst +++ /dev/null @@ -1,23 +0,0 @@ -class Problem { - constructor(title, detail, status) { - this.title = title - this.detail = detail - this.status = status - } - - // note: Javascript errors return status 400 (Bad request) in the client - // version of Problem, 500 (Internal server error) in the server version - static from(error) { - return ( - error instanceof Problem ? - error : - new Problem( - 'Internal server error', - (error.stack || error.message), - 500 - ) - ) - } -} - -return Problem diff --git a/_lib/post_request.jst b/_lib/post_request.jst index 484f1b9..1757f86 100644 --- a/_lib/post_request.jst +++ b/_lib/post_request.jst @@ -1,70 +1,32 @@ +let jst_server = (await import('@ndcode/jst_server')).default let stream_buffers = require('stream-buffers') return async (env, handler) => { - let Problem = await _require('/_lib/Problem.jst') - - let result - try { - if (env.request.method !== 'POST') { - env.response.setHeader('Allow', 'POST') - throw new Problem( - 'Method not allowed', - `The endpoint "${env.parsed_url.path}" requires a POST request.`, - 405 - ) - } - - let write_stream = new stream_buffers.WritableStreamBuffer() - let data = new Promise( - (resolve, reject) => { - write_stream. - on('finish', () => {resolve(write_stream.getContents())}). - on('error', () => {reject()}) - } + if (env.request.method !== 'POST') { + env.response.setHeader('Allow', 'POST') + throw new jst_server.Problem( + 'Method not allowed', + `The endpoint "${env.parsed_url.path}" requires a POST request.`, + 405 ) - env.request.pipe(write_stream) - let args = JSON.parse((await data).toString('utf-8')) - console.log('endpoint', env.parsed_url.path, 'args', JSON.stringify(args)) - - result = await handler(...args) - if (result === undefined) - result = null - console.log('endpoint', env.parsed_url.path, 'result', JSON.stringify(result)) } - catch (error) { - let problem = - error instanceof Problem ? - error : - new Problem( - // title - 'Internal server error', - // details - (error.stack || error.message).toString() - // status - 500 - ) - console.log('endpoint', env.parsed_url.path, 'problem', problem.detail) - env.mime_type = 'application/problem+json; charset=utf-8' - env.site.serve( - env, - problem.status, - Buffer.from( - JSON.stringify( - { - title: problem.title, - detail: problem.detail, - status: problem.status - }, - null, - 2 - ) + '\n', - 'utf-8' - ), - 'post_request.jst' - ) - return - } + let write_stream = new stream_buffers.WritableStreamBuffer() + let data = new Promise( + (resolve, reject) => { + write_stream. + on('finish', () => {resolve(write_stream.getContents())}). + on('error', () => {reject()}) + } + ) + env.request.pipe(write_stream) + let args = JSON.parse((await data).toString('utf-8')) + console.log('endpoint', env.parsed_url.path, 'args', JSON.stringify(args)) + + let result = await handler(...args) + if (result === undefined) + result = null + console.log('endpoint', env.parsed_url.path, 'result', JSON.stringify(result)) env.site.serve( env, diff --git a/api/account/change_details/get.json.jst b/api/account/change_details/get.json.jst index 80892b6..19fb032 100644 --- a/api/account/change_details/get.json.jst +++ b/api/account/change_details/get.json.jst @@ -1,10 +1,10 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let get_account = await _require('/_lib/get_account.jst') let get_session = await _require('/_lib/get_session.jst') let post_request = await _require('/_lib/post_request.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -18,7 +18,11 @@ return async env => { let account = await get_account(root, session) if (account === undefined) - throw new Problem('Unauthorized', 'Please sign in first.', 401) + throw new jst_server.Problem( + 'Unauthorized', + 'Please sign in first.', + 401 + ) return { given_names: await account.get_json('given_names'), diff --git a/api/account/change_details/get_draft.json.jst b/api/account/change_details/get_draft.json.jst index 1afa16e..a168014 100644 --- a/api/account/change_details/get_draft.json.jst +++ b/api/account/change_details/get_draft.json.jst @@ -1,9 +1,9 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let post_request = await _require('/_lib/post_request.jst') let get_session = await _require('/_lib/get_session.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env diff --git a/api/account/change_details/set.json.jst b/api/account/change_details/set.json.jst index 109e84e..e3de45c 100644 --- a/api/account/change_details/set.json.jst +++ b/api/account/change_details/set.json.jst @@ -1,10 +1,10 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let get_account = await _require('/_lib/get_account.jst') let get_session = await _require('/_lib/get_session.jst') let post_request = await _require('/_lib/post_request.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -17,7 +17,7 @@ return async env => { contact_me: details.contact_me ? true : false } if (details.given_names.length === 0) - throw new Problem( + throw new jst_server.Problem( 'Bad request', 'Minimum length check failed', 400 @@ -30,7 +30,11 @@ return async env => { let account = await get_account(root, session) if (account === undefined) - throw new Problem('Unauthorized', 'Please sign in first.', 401) + throw new jst_server.Problem( + 'Unauthorized', + 'Please sign in first.', + 401 + ) account.set_json('given_names', details.given_names) account.set_json('family_name', details.family_name) diff --git a/api/account/change_details/set_draft.json.jst b/api/account/change_details/set_draft.json.jst index ada7fe1..76503c6 100644 --- a/api/account/change_details/set_draft.json.jst +++ b/api/account/change_details/set_draft.json.jst @@ -1,9 +1,9 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let post_request = await _require('/_lib/post_request.jst') let get_session = await _require('/_lib/get_session.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env diff --git a/api/account/change_password.json.jst b/api/account/change_password.json.jst index 6c06323..2bba98a 100644 --- a/api/account/change_password.json.jst +++ b/api/account/change_password.json.jst @@ -1,11 +1,11 @@ let crypto = require('crypto') +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let get_account = await _require('/_lib/get_account.jst') let get_session = await _require('/_lib/get_session.jst') let post_request = await _require('/_lib/post_request.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -16,7 +16,7 @@ return async env => { old_password = old_password.slice(0, 256) new_password = new_password.slice(0, 256) if (old_password.length < 8 || new_password.length < 8) - throw new Problem( + throw new jst_server.Problem( 'Bad request', 'Minimum length check failed', 400 @@ -29,10 +29,14 @@ return async env => { let account = await get_account(root, session) if (account === undefined) - throw new Problem('Unauthorized', 'Please sign in first.', 401) + throw new jst_server.Problem( + 'Unauthorized', + 'Please sign in first.', + 401 + ) if (old_password !== await account.get_json('password')) - throw new Problem( + throw new jst_server.Problem( 'Incorrect password', `Provided old password did not match the expected value.`, 426 diff --git a/api/account/password_reset.json.jst b/api/account/password_reset.json.jst index fbefab4..ec15432 100644 --- a/api/account/password_reset.json.jst +++ b/api/account/password_reset.json.jst @@ -1,10 +1,10 @@ let crypto = require('crypto') +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let get_nodemailer = await _require('/_lib/get_nodemailer.jst') let post_request = await _require('/_lib/post_request.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -15,7 +15,7 @@ return async env => { email = email.slice(0, 256).toLowerCase() password = password.slice(0, 256) if (email.length === 0 || password.length < 8) - throw new Problem( + throw new jst_server.Problem( 'Bad request', 'Minimum length check failed', 400 @@ -31,7 +31,7 @@ return async env => { let accounts = await root.get('accounts', {}) let account = await accounts.get(email) if (account === undefined) - throw new Problem( + throw new jst_server.Problem( 'Account does not exist', `Please create the account for "${email}" before attempting to reset its password.` 421 diff --git a/api/account/sign_in.json.jst b/api/account/sign_in.json.jst index 30a5bd1..e35392f 100644 --- a/api/account/sign_in.json.jst +++ b/api/account/sign_in.json.jst @@ -1,7 +1,8 @@ +let jst_server = (await import('@ndcode/jst_server')).default + return async env => { let post_request = await _require('/_lib/post_request.jst') let get_session = await _require('/_lib/get_session.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -12,7 +13,7 @@ return async env => { email = email.slice(0, 256).toLowerCase() password = password.slice(0, 256) if (email.length === 0 || password.length < 8) - throw new Problem( + throw new jst_server.Problem( 'Bad request', 'Minimum length check failed', 400 @@ -28,14 +29,14 @@ return async env => { account === undefined || password !== await account.get_json('password') ) - throw new Problem( + throw new jst_server.Problem( 'Unauthorized', 'Email and password combination was incorrect.' 401 ) if (!await account.get_json('email_verified')) - throw new Problem( + throw new jst_server.Problem( 'Email not yet verified', 'Please verify your email address via email link before trying to sign in.', 425 diff --git a/api/account/sign_out.json.jst b/api/account/sign_out.json.jst index 70287a3..eaeedf1 100644 --- a/api/account/sign_out.json.jst +++ b/api/account/sign_out.json.jst @@ -1,7 +1,8 @@ +let jst_server = (await import('@ndcode/jst_server')).default + return async env => { let post_request = await _require('/_lib/post_request.jst') let get_session = await _require('/_lib/get_session.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env diff --git a/api/account/sign_up/create_account.json.jst b/api/account/sign_up/create_account.json.jst index 2685f30..2eb3efe 100644 --- a/api/account/sign_up/create_account.json.jst +++ b/api/account/sign_up/create_account.json.jst @@ -1,9 +1,9 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let post_request = await _require('/_lib/post_request.jst') let get_session = await _require('/_lib/get_session.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -24,7 +24,7 @@ return async env => { details.given_names.length === 0 || details.password.length < 8 ) - throw new Problem( + throw new jst_server.Problem( 'Bad request', 'Minimum length check failed', 400 @@ -40,7 +40,7 @@ return async env => { captcha === undefined || XDate.now() >= await captcha.get_json('expires') ) - throw new Problem( + throw new jst_server.Problem( 'No verification image in session', `Please call the "/api/verification_image.png" endpoint to create a verification image, in same session as the "/api/account/sign_up/create_account.json" call and less than one hour prior.`, 418 @@ -50,7 +50,7 @@ return async env => { if (verification_code !== captcha_text) { console.log(`verification code mismatch, \"${verification_code}\" should be \"${captcha_text}\"`) - throw new Problem( + throw new jst_server.Problem( 'Verification code mismatch', `The provided verification code "${verification_code}" did not match the verification image.`, 419 @@ -59,7 +59,7 @@ return async env => { let accounts = await root.get('accounts', {}) if (accounts.has(details.email)) - throw new Problem( + throw new jst_server.Problem( 'Account already exists', `The email "${details.email}" already has an account registered.`, 420 diff --git a/api/account/sign_up/get_draft.json.jst b/api/account/sign_up/get_draft.json.jst index cf696b8..9649f6c 100644 --- a/api/account/sign_up/get_draft.json.jst +++ b/api/account/sign_up/get_draft.json.jst @@ -1,9 +1,9 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let post_request = await _require('/_lib/post_request.jst') let get_session = await _require('/_lib/get_session.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env diff --git a/api/account/sign_up/send_email_verification_link.json.jst b/api/account/sign_up/send_email_verification_link.json.jst index c1d052f..5b45149 100644 --- a/api/account/sign_up/send_email_verification_link.json.jst +++ b/api/account/sign_up/send_email_verification_link.json.jst @@ -1,10 +1,10 @@ let crypto = require('crypto') +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let get_nodemailer = await _require('/_lib/get_nodemailer.jst') let post_request = await _require('/_lib/post_request.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -14,7 +14,7 @@ return async env => { // coerce and/or validate email = email.slice(0, 256).toLowerCase() if (email.length === 0) - throw new Problem( + throw new jst_server.Problem( 'Bad request', 'Minimum length check failed', 400 @@ -30,14 +30,14 @@ return async env => { let accounts = await root.get('accounts', {}) let account = await accounts.get(email) if (account === undefined) - throw new Problem( + throw new jst_server.Problem( 'Account does not exist', `Please create the account for "${email}" before attempting to send an email verification link.` 421 ) if (await account.get_json('email_verified')) - throw new Problem( + throw new jst_server.Problem( 'Email already verified', `Your email "${email}" is already verified. You can now sign in.` 422 diff --git a/api/account/sign_up/set_draft.json.jst b/api/account/sign_up/set_draft.json.jst index b777ac7..ac20f8e 100644 --- a/api/account/sign_up/set_draft.json.jst +++ b/api/account/sign_up/set_draft.json.jst @@ -1,9 +1,9 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let post_request = await _require('/_lib/post_request.jst') let get_session = await _require('/_lib/get_session.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env diff --git a/api/account/sign_up/verify_email.json.jst b/api/account/sign_up/verify_email.json.jst index 2517749..c0f2fc3 100644 --- a/api/account/sign_up/verify_email.json.jst +++ b/api/account/sign_up/verify_email.json.jst @@ -1,9 +1,9 @@ let crypto = require('crypto') +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let post_request = await _require('/_lib/post_request.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -14,7 +14,7 @@ return async env => { email = email.slice(0, 256).toLowerCase() link_code = link_code.slice(0, 256).toLowerCase() if (email.length === 0 || link_code.length < 32) - throw new Problem( + throw new jst_server.Problem( 'Bad request', 'Minimum length check failed', 400 @@ -26,14 +26,14 @@ return async env => { let accounts = await root.get('accounts', {}) let account = await accounts.get(email) if (account === undefined) - throw new Problem( + throw new jst_server.Problem( 'Account does not exist', `Please create the account for "${email}" before attempting to verify the email verification link.` 421 ) if (await account.get_json('email_verified')) - throw new Problem( + throw new jst_server.Problem( 'Email already verified', `Your email "${email}" is already verified. You can now sign in.` 422 @@ -44,13 +44,13 @@ return async env => { verify_email === undefined || XDate.now() >= await verify_email.get_json('expires') ) - throw new Problem( + throw new jst_server.Problem( 'Link code missing', `Email verification link code for account "${email}" does not exist or has expired.`, 423 ) if (link_code !== await verify_email.get_json('link_code')) - throw new Problem( + throw new jst_server.Problem( 'Link code mismatch', `Provided email verification link code "${link_code}" does not match expected value.`, 423 diff --git a/api/account/verify_password.json.jst b/api/account/verify_password.json.jst index ca0d76a..7b7ea25 100644 --- a/api/account/verify_password.json.jst +++ b/api/account/verify_password.json.jst @@ -1,9 +1,9 @@ let crypto = require('crypto') +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let post_request = await _require('/_lib/post_request.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -14,7 +14,7 @@ return async env => { email = email.slice(0, 256).toLowerCase() link_code = link_code.slice(0, 256).toLowerCase() if (email.length === 0 || link_code.length < 32) - throw new Problem( + throw new jst_server.Problem( 'Bad request', 'Minimum length check failed', 400 @@ -26,7 +26,7 @@ return async env => { let accounts = await root.get('accounts', {}) let account = await accounts.get(email) if (account === undefined) - throw new Problem( + throw new jst_server.Problem( 'Account does not exist', `Please create the account for "${email}" before attempting to verify the password reset link.` 421 @@ -37,13 +37,13 @@ return async env => { verify_password === undefined || XDate.now() >= await verify_password.get_json('expires') ) - throw new Problem( + throw new jst_server.Problem( 'Link code missing', `Password reset link code for account "${email}" does not exist or has expired.`, 423 ) if (link_code !== await verify_password.get_json('link_code')) - throw new Problem( + throw new jst_server.Problem( 'Link code mismatch', `Provided password reset link code "${link_code}" does not match expected value.`, 423 diff --git a/api/contact/get_draft.json.jst b/api/contact/get_draft.json.jst index af5502a..da507fa 100644 --- a/api/contact/get_draft.json.jst +++ b/api/contact/get_draft.json.jst @@ -1,9 +1,9 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let post_request = await _require('/_lib/post_request.jst') let get_session = await _require('/_lib/get_session.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env diff --git a/api/contact/send_enquiry.json.jst b/api/contact/send_enquiry.json.jst index 137210d..daa735b 100644 --- a/api/contact/send_enquiry.json.jst +++ b/api/contact/send_enquiry.json.jst @@ -1,9 +1,9 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let get_nodemailer = await _require('/_lib/get_nodemailer.jst') let post_request = await _require('/_lib/post_request.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -23,7 +23,7 @@ return async env => { details.email.length === 0 || details.message.length === 0 ) - throw new Problem( + throw new jst_server.Problem( 'Bad request', 'Minimum length check failed', 400 diff --git a/api/contact/set_draft.json.jst b/api/contact/set_draft.json.jst index 2f8af42..a515d67 100644 --- a/api/contact/set_draft.json.jst +++ b/api/contact/set_draft.json.jst @@ -1,9 +1,9 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let post_request = await _require('/_lib/post_request.jst') let get_session = await _require('/_lib/get_session.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env diff --git a/api/globals/get.json.jst b/api/globals/get.json.jst index 155fab4..b8c52a5 100644 --- a/api/globals/get.json.jst +++ b/api/globals/get.json.jst @@ -1,10 +1,10 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let get_account = await _require('/_lib/get_account.jst') let get_session = await _require('/_lib/get_session.jst') let post_request = await _require('/_lib/post_request.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -18,9 +18,17 @@ return async env => { let account = await get_account(root, session) if (account === undefined) - throw new Problem('Unauthorized', 'Please sign in first.', 401) + throw new jst_server.Problem( + 'Unauthorized', + 'Please sign in first.', + 401 + ) if (!await account.get_json('administrator')) - throw new Problem('Unauthorized', 'Not administrator.', 401) + throw new jst_server.Problem( + 'Unauthorized', + 'Not administrator.', + 401 + ) return /*await*/ root.get_json('globals', {}) } diff --git a/api/globals/set.json.jst b/api/globals/set.json.jst index 5949fe2..e1bea58 100644 --- a/api/globals/set.json.jst +++ b/api/globals/set.json.jst @@ -1,9 +1,9 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let post_request = await _require('/_lib/post_request.jst') let get_session = await _require('/_lib/get_session.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -30,9 +30,17 @@ return async env => { let account = await get_account(root, session) if (account === undefined) - throw new Problem('Unauthorized', 'Please sign in first.', 401) + throw new jst_server.Problem( + 'Unauthorized', + 'Please sign in first.', + 401 + ) if (!await account.get_json('administrator')) - throw new Problem('Unauthorized', 'Not administrator.', 401) + throw new jst_server.Problem( + 'Unauthorized', + 'Not administrator.', + 401 + ) root.set_json('globals', globals) await transaction.commit() diff --git a/api/nodemailers/get.json.jst b/api/nodemailers/get.json.jst index 2aa640c..8030196 100644 --- a/api/nodemailers/get.json.jst +++ b/api/nodemailers/get.json.jst @@ -1,10 +1,10 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let get_account = await _require('/_lib/get_account.jst') let get_session = await _require('/_lib/get_session.jst') let post_request = await _require('/_lib/post_request.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -18,9 +18,17 @@ return async env => { let account = await get_account(root, session) if (account === undefined) - throw new Problem('Unauthorized', 'Please sign in first.', 401) + throw new jst_server.Problem( + 'Unauthorized', + 'Please sign in first.', + 401 + ) if (!await account.get_json('administrator')) - throw new Problem('Unauthorized', 'Not administrator.', 401) + throw new jst_server.Problem( + 'Unauthorized', + 'Not administrator.', + 401 + ) return /*await*/ root.get_json('nodemailers', {}) } diff --git a/api/nodemailers/set.json.jst b/api/nodemailers/set.json.jst index 808fe5b..ab57981 100644 --- a/api/nodemailers/set.json.jst +++ b/api/nodemailers/set.json.jst @@ -1,10 +1,10 @@ +let jst_server = (await import('@ndcode/jst_server')).default let XDate = require('xdate') return async env => { let get_account = await _require('/_lib/get_account.jst') let get_session = await _require('/_lib/get_session.jst') let post_request = await _require('/_lib/post_request.jst') - let Problem = await _require('/_lib/Problem.jst') await post_request( // env @@ -21,9 +21,17 @@ return async env => { let account = await get_account(root, session) if (account === undefined) - throw new Problem('Unauthorized', 'Please sign in first.', 401) + throw new jst_server.Problem( + 'Unauthorized', + 'Please sign in first.', + 401 + ) if (!await account.get_json('administrator')) - throw new Problem('Unauthorized', 'Not administrator.', 401) + throw new jst_server.Problem( + 'Unauthorized', + 'Not administrator.', + 401 + ) root.set_json('nodemailers', nodemailers) await transaction.commit() diff --git a/link.sh b/link.sh index de4f402..8eec3cd 100755 --- a/link.sh +++ b/link.sh @@ -1,5 +1,5 @@ #!/bin/sh rm -rf node_modules package-lock.json -npm link @ndcode/logjson @ndcode/nodemailer_cache @ndcode/zettair_cache +npm link @ndcode/jst_server @ndcode/logjson @ndcode/zettair_cache npm install npm link diff --git a/package.json b/package.json index f31e278..4792a60 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Example website using JavaScript Template system", "directories": {}, "dependencies": { + "@ndcode/jst_server": "^0.1.0", "@ndcode/logjson": "^0.1.0", "@ndcode/zettair_cache": "^0.1.0", "captchagen": "^1.2.0", -- 2.34.1