allow cors context.json (#339)

This commit is contained in:
phiresky 2024-07-15 15:41:14 +02:00 committed by GitHub
parent f3509a3e70
commit e0d824cac9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,9 @@
import express, { RequestHandler, Request, Response } from "express"; import express, {
RequestHandler,
Request,
Response,
NextFunction,
} from "express";
import { StaticRouter } from "inferno-router"; import { StaticRouter } from "inferno-router";
import { renderToString } from "inferno-server"; import { renderToString } from "inferno-server";
// import { matchPath } from "inferno-router"; // import { matchPath } from "inferno-router";
@ -12,6 +17,11 @@ import { getLanguageFromCookie, i18n } from "../shared/i18next";
const server = express(); const server = express();
const port = 1234; const port = 1234;
function cors(_req: Request, res: Response, next: NextFunction): void {
res.header("Access-Control-Allow-Origin", "*");
next();
}
server.use(express.json() as RequestHandler); server.use(express.json() as RequestHandler);
server.use(express.urlencoded({ extended: false }) as RequestHandler); server.use(express.urlencoded({ extended: false }) as RequestHandler);
server.use("/static", express.static(path.resolve("./dist"))); server.use("/static", express.static(path.resolve("./dist")));
@ -19,6 +29,7 @@ server.use("/docs", express.static(path.resolve("./dist/assets/docs")));
server.use("/api", express.static(path.resolve("./dist/assets/api"))); server.use("/api", express.static(path.resolve("./dist/assets/api")));
server.use( server.use(
"/context.json", "/context.json",
cors,
express.static(path.resolve("./dist/assets/lemmy_federation_context.json")), express.static(path.resolve("./dist/assets/lemmy_federation_context.json")),
); );
server.use("/feed.xml", express.static(path.resolve("./dist/feed.xml"))); server.use("/feed.xml", express.static(path.resolve("./dist/feed.xml")));