-
Notifications
You must be signed in to change notification settings - Fork 3
/
dev.ts
36 lines (33 loc) · 1.06 KB
/
dev.ts
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 * as http from "http";
import * as esbuild from "esbuild";
import * as path from "path";
(async () => {
const ctx = await esbuild.context({
define: { JE2BE_VERSION: '"(local)"' },
entryPoints: [path.join(__dirname, "src/front/component/index.tsx")],
bundle: true,
outfile: path.join(__dirname, "public", "script", "front.js"),
});
const { host, port } = await ctx.serve({
servedir: path.join(__dirname, "public"),
});
http
.createServer((req, res) => {
const options = {
hostname: host,
port: port,
path: req.url,
method: req.method,
headers: req.headers,
};
const proxyReq = http.request(options, (proxyRes) => {
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
res.writeHead(proxyRes.statusCode ?? 500, proxyRes.headers);
proxyRes.pipe(res, { end: true });
});
req.pipe(proxyReq, { end: true });
})
.listen(3000);
console.log(`http://localhost:3000`);
})();