-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.ts
More file actions
36 lines (31 loc) · 729 Bytes
/
server.ts
File metadata and controls
36 lines (31 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Koa from 'koa'
import logger from 'koa-logger'
import parser from './src'
import { File } from 'formidable'
const port = 3000
const app = new Koa()
app.use(logger())
app.use(
parser({
error (err, ctx): void {
console.log(err)
ctx.throw('custom parse error', 422)
}
})
)
app.use(
async (ctx: Koa.Context, next): Promise<void> => {
if (ctx.request.body !== undefined) {
if (ctx.request.body.file) {
const file: File = ctx.request.body.file
console.log(file)
console.log(file.toJSON())
console.log(file.lastModifiedDate)
}
ctx.body = ctx.request.body
}
await next()
}
)
app.listen(port)
console.error(`listening on port ${port}`)