- 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))