-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (42 loc) · 1.07 KB
/
index.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* tslint:disable */
/* eslint-disable */
/* prettier-ignore */
const astroSurf = require("./astro-surf")
const AstroSurf = {
initialize: (handler, opt = {
client_path: './dist/client',
}) => {
let surf = astroSurf.AppFactory.initialize(async (ctx) => {
let body = []
let status = 200;
let headers = {};
let astrohandler = () => {
return new Promise((resolve) => {
ctx.response['writeHead'] = (status, header) => {
status = status;
headers = { ...headers, ...header }
}
ctx.response['write'] = (uint8_array) => {
body.push(...uint8_array);
}
ctx.response['end'] = () => {
resolve(true);
}
handler(ctx.request, ctx.response);
})
}
await astrohandler();
return [
status,
headers,
body
];
}, opt.client_path || "./dist/client");
return {
serve: async (port, host = '127.0.0.1') => {
await surf.serve(port, host)
}
}
}
}
module.exports = AstroSurf