mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-29 13:27:31 -07:00
split routers
This commit is contained in:
parent
0f928bfb23
commit
e58b839339
2 changed files with 25 additions and 15 deletions
|
@ -19,19 +19,11 @@ import signupPending from "./private/signup-pending.js";
|
|||
import discord from "./service/discord.js";
|
||||
import github from "./service/github.js";
|
||||
import twitter from "./service/twitter.js";
|
||||
import koaBody from "koa-body";
|
||||
|
||||
// Init app
|
||||
const app = new Koa();
|
||||
|
||||
// Init multer instance
|
||||
const upload = multer({
|
||||
storage: multer.diskStorage({}),
|
||||
limits: {
|
||||
fileSize: config.maxFileSize || 262144000,
|
||||
files: 1,
|
||||
},
|
||||
});
|
||||
|
||||
app.use(
|
||||
cors({
|
||||
origin: "*",
|
||||
|
@ -44,7 +36,20 @@ app.use(async (ctx, next) => {
|
|||
await next();
|
||||
});
|
||||
|
||||
app.use(
|
||||
// Init router
|
||||
const router = new Router();
|
||||
const mastoRouter = new Router();
|
||||
|
||||
// Init multer instance
|
||||
const upload = multer({
|
||||
storage: multer.diskStorage({}),
|
||||
limits: {
|
||||
fileSize: config.maxFileSize || 262144000,
|
||||
files: 1,
|
||||
},
|
||||
});
|
||||
|
||||
router.use(
|
||||
bodyParser({
|
||||
// リクエストが multipart/form-data でない限りはJSONだと見なす
|
||||
detectJSON: (ctx) =>
|
||||
|
@ -55,10 +60,9 @@ app.use(
|
|||
}),
|
||||
);
|
||||
|
||||
// Init router
|
||||
const router = new Router();
|
||||
mastoRouter.use(koaBody());
|
||||
|
||||
apiMastodonCompatible(router);
|
||||
apiMastodonCompatible(mastoRouter);
|
||||
|
||||
/**
|
||||
* Register endpoint handlers
|
||||
|
@ -150,5 +154,6 @@ router.all("(.*)", async (ctx) => {
|
|||
|
||||
// Register router
|
||||
app.use(router.routes());
|
||||
app.use(mastoRouter.routes());
|
||||
|
||||
export default app;
|
||||
|
|
|
@ -29,6 +29,7 @@ import fileServer from "./file/index.js";
|
|||
import proxyServer from "./proxy/index.js";
|
||||
import webServer from "./web/index.js";
|
||||
import { initializeStreamingServer } from "./api/streaming.js";
|
||||
import koaBody from "koa-body";
|
||||
|
||||
export const serverLogger = new Logger("server", "gray", false);
|
||||
|
||||
|
@ -69,6 +70,9 @@ app.use(mount("/proxy", proxyServer));
|
|||
|
||||
// Init router
|
||||
const router = new Router();
|
||||
const mastoRouter = new Router();
|
||||
|
||||
mastoRouter.use(koaBody());
|
||||
|
||||
// Routing
|
||||
router.use(activityPub.routes());
|
||||
|
@ -134,13 +138,13 @@ router.get("/verify-email/:code", async (ctx) => {
|
|||
}
|
||||
});
|
||||
|
||||
router.get("/oauth/authorize", async (ctx) => {
|
||||
mastoRouter.get("/oauth/authorize", async (ctx) => {
|
||||
const client_id = ctx.request.query.client_id;
|
||||
console.log(ctx.request.req);
|
||||
ctx.redirect(Buffer.from(client_id?.toString() || '', 'base64').toString());
|
||||
});
|
||||
|
||||
router.post("/oauth/token", async (ctx) => {
|
||||
mastoRouter.post("/oauth/token", async (ctx) => {
|
||||
const body: any = ctx.request.body;
|
||||
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
|
||||
const generator = (megalodon as any).default;
|
||||
|
@ -167,6 +171,7 @@ router.post("/oauth/token", async (ctx) => {
|
|||
|
||||
// Register router
|
||||
app.use(router.routes());
|
||||
app.use(mastoRouter.routes());
|
||||
|
||||
app.use(mount(webServer));
|
||||
|
||||
|
|
Loading…
Reference in a new issue