Enable cors only for :lang

This commit is contained in:
plondon 2021-09-25 10:57:11 -04:00
parent a181f5d6f0
commit 4ad30023f5
1 changed files with 2 additions and 4 deletions

View File

@ -21,9 +21,6 @@ const fathomSiteId = process.env.FATHOM_SITE_ID || "";
const langs = await langsPromise;
const app = express();
app.use(cors());
app.options("*", cors());
app.set("query parser", (qs) => new URLSearchParams(qs));
app.set("view engine", "ejs");
@ -48,7 +45,8 @@ for (const [lang, { aliases }] of Object.entries(langs)) {
}
}
}
app.get("/:lang", (req, res) => {
app.options('/:lang', cors())
app.get("/:lang", cors(), (req, res) => {
const lang = req.params.lang;
const lowered = lang.toLowerCase();
if (lowered !== lang) {