split routers
This commit is contained in:
parent
8fdd3e09c6
commit
d103d69727
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 discord from "./service/discord.js";
|
||||||
import github from "./service/github.js";
|
import github from "./service/github.js";
|
||||||
import twitter from "./service/twitter.js";
|
import twitter from "./service/twitter.js";
|
||||||
|
import koaBody from "koa-body";
|
||||||
|
|
||||||
// Init app
|
// Init app
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
|
|
||||||
// Init multer instance
|
|
||||||
const upload = multer({
|
|
||||||
storage: multer.diskStorage({}),
|
|
||||||
limits: {
|
|
||||||
fileSize: config.maxFileSize || 262144000,
|
|
||||||
files: 1,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
cors({
|
cors({
|
||||||
origin: "*",
|
origin: "*",
|
||||||
|
@ -44,7 +36,20 @@ app.use(async (ctx, next) => {
|
||||||
await 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({
|
bodyParser({
|
||||||
// リクエストが multipart/form-data でない限りはJSONだと見なす
|
// リクエストが multipart/form-data でない限りはJSONだと見なす
|
||||||
detectJSON: (ctx) =>
|
detectJSON: (ctx) =>
|
||||||
|
@ -55,10 +60,9 @@ app.use(
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Init router
|
mastoRouter.use(koaBody());
|
||||||
const router = new Router();
|
|
||||||
|
|
||||||
apiMastodonCompatible(router);
|
apiMastodonCompatible(mastoRouter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register endpoint handlers
|
* Register endpoint handlers
|
||||||
|
@ -150,5 +154,6 @@ router.all("(.*)", async (ctx) => {
|
||||||
|
|
||||||
// Register router
|
// Register router
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
|
app.use(mastoRouter.routes());
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|
|
@ -29,6 +29,7 @@ import fileServer from "./file/index.js";
|
||||||
import proxyServer from "./proxy/index.js";
|
import proxyServer from "./proxy/index.js";
|
||||||
import webServer from "./web/index.js";
|
import webServer from "./web/index.js";
|
||||||
import { initializeStreamingServer } from "./api/streaming.js";
|
import { initializeStreamingServer } from "./api/streaming.js";
|
||||||
|
import koaBody from "koa-body";
|
||||||
|
|
||||||
export const serverLogger = new Logger("server", "gray", false);
|
export const serverLogger = new Logger("server", "gray", false);
|
||||||
|
|
||||||
|
@ -69,6 +70,9 @@ app.use(mount("/proxy", proxyServer));
|
||||||
|
|
||||||
// Init router
|
// Init router
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
const mastoRouter = new Router();
|
||||||
|
|
||||||
|
mastoRouter.use(koaBody());
|
||||||
|
|
||||||
// Routing
|
// Routing
|
||||||
router.use(activityPub.routes());
|
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;
|
const client_id = ctx.request.query.client_id;
|
||||||
console.log(ctx.request.req);
|
console.log(ctx.request.req);
|
||||||
ctx.redirect(Buffer.from(client_id?.toString() || '', 'base64').toString());
|
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 body: any = ctx.request.body;
|
||||||
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
|
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
|
||||||
const generator = (megalodon as any).default;
|
const generator = (megalodon as any).default;
|
||||||
|
@ -167,6 +171,7 @@ router.post("/oauth/token", async (ctx) => {
|
||||||
|
|
||||||
// Register router
|
// Register router
|
||||||
app.use(router.routes());
|
app.use(router.routes());
|
||||||
|
app.use(mastoRouter.routes());
|
||||||
|
|
||||||
app.use(mount(webServer));
|
app.use(mount(webServer));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue