This repository was archived by the owner on Dec 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
44 lines (35 loc) · 1.27 KB
/
Copy pathindex.ts
File metadata and controls
44 lines (35 loc) · 1.27 KB
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
import {Hono} from "hono";
import {runFunction} from "./inc/lib";
const defaultProject = process.env.DEFAULT_PROJECT ?? '';
const defaultFunction = process.env.DEFAULT_FUNCTION ?? '';
const prefixedPath = process.env.PATH_INSTEAD_OF_DOMAIN === 'true' ? (process.env.PATH_PREFIX ?? '') : '';
const app = new Hono({strict: false}).basePath(`/${prefixedPath}`);
if (process.env.ALLOW_GLOBAL === 'true') {
// Project and function route
app.all('/:project/:functionId', async (c) => {
return await runFunction(c.req.param().project, c.req.param().functionId, c);
});
if (process.env.PATH_AS_DATA === 'true') {
app.all('/:project/:functionId/:pathData', async (c) => {
return await runFunction(c.req.param().project, c.req.param().functionId, c, c.req.param().pathData);
});
}
}
// Default function
app.all('/', async (c) => {
return await runFunction(defaultProject, defaultFunction, c);
});
if (process.env.PATH_AS_DATA === 'true') {
app.all('/:pathData', async (c) => {
return await runFunction(defaultProject, defaultFunction, c, c.req.param().pathData);
});
}
// Error 404
app.all('*', (c) => {
console.log(c);
return c.json({'NotFound': true}, 404);
});
Bun.serve({
port : 3000,
fetch: app.fetch,
});