-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
30 lines (27 loc) · 821 Bytes
/
example.js
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
import Server, { Body, StatusMode } from './dist/AutomatonServer.js';
import fs from 'fs';
let server = new Server();
server.config.statusMode = StatusMode.EXTENDED;
server.serve('/', './');
server
.api('api')
.post('file', Body.BLOB, async (reply, {body})=>{
console.log(body);
return await reply.json({});
})
.post('array', Body.STREAM, async (reply, {body})=>{
console.log("writing");
// write the file to disk
await new Promise(res=>{
let stream = fs.createWriteStream('./output.zip')
body.pipe(stream);
body.on('end',res);
})
console.log("written");
//fs.writeFile('./output.zip', body, null, ()=>{console.log("done")});
return await reply.json({});
})
.get('item/{id:number}', async (reply, {id})=>{
return await reply.json({id: id});
});
server.start(80);