-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathindex.tsx
66 lines (55 loc) · 1.83 KB
/
index.tsx
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import "./logging";
import { join, relative } from "node:path";
import { federation } from "@fedify/fedify/x/hono";
import { serveStatic } from "@hono/node-server/serve-static";
import { captureException } from "@sentry/core";
import { Hono } from "hono";
import { cors } from "hono/cors";
import api from "./api";
import fedi from "./federation";
import image from "./image";
import oauth, { oauthAuthorizationServer } from "./oauth";
import pages from "./pages";
import { DRIVE_DISK, FS_STORAGE_PATH } from "./storage";
const app = new Hono();
app.onError((err, _) => {
captureException(err);
throw err;
});
if (DRIVE_DISK === "fs") {
app.use(
"/assets/*",
serveStatic({
root: relative(process.cwd(), FS_STORAGE_PATH!),
rewriteRequestPath: (path) => path.substring("/assets".length),
}),
);
}
app.use(
"/public/*",
serveStatic({
root: relative(process.cwd(), join(import.meta.dirname, "public")),
rewriteRequestPath: (path) => path.substring("/public".length),
}),
);
const CorsPolicy = (allowMethods: string[]) =>
cors({
origin: "*",
allowMethods: allowMethods,
});
// Mastodon's CORS policy also allows `/@:username` and `/users/:username`
// the /api router adds its own cors policy middleware:
app.use("/.well-known/*", CorsPolicy(["GET"]));
app.use("/nodeinfo/*", CorsPolicy(["GET"]));
app.use("/oauth/token", CorsPolicy(["POST"]));
// Hollo doesn't support token revocation currently:
// app.use("/oauth/revoke", CorsPolicy(["POST"]));
app.use("/oauth/userinfo", CorsPolicy(["GET", "POST"]));
app.use(federation(fedi, (_) => undefined));
app.route("/", pages);
app.route("/oauth", oauth);
app.route("/api", api);
app.route("/image", image);
app.get("/.well-known/oauth-authorization-server", oauthAuthorizationServer);
app.get("/nodeinfo/2.0", (c) => c.redirect("/nodeinfo/2.1"));
export default app;