-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·42 lines (35 loc) · 973 Bytes
/
server.js
File metadata and controls
executable file
·42 lines (35 loc) · 973 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
37
38
39
40
41
42
#!/usr/bin/env node
import { serveStatic } from '@hono/node-server/serve-static';
import { serve } from '@hono/node-server';
import { Hono } from 'hono';
import { join } from 'node:path';
import { proxy } from 'hono/proxy';
const app = new Hono();
if (process.argv[2] === 'proxy') {
const baseURL = process.argv[3] ?? 'https://xenodrive.github.io/vis';
console.log('Proxy to ' + baseURL);
app.use('*', (c) => {
const url = new URL(baseURL);
url.pathname = url.pathname.replace(/\/$/, '') + c.req.path;
const q = c.req.queries();
for (const k in q) {
for (const v of q?.[k] ?? []) {
url.searchParams.append(k, v);
}
}
return proxy(url, {
...c.req,
});
});
} else {
app.use('*', serveStatic({ root: join(import.meta.dirname, 'dist/') }));
}
serve(
{
fetch: app.fetch,
port: process.env.VIS_PORT || 3000,
},
(info) => {
console.log(`Listening on http://localhost:${info.port}`);
},
);