diff --git a/commands/api.js b/commands/api.js index d642d12..aecba0e 100644 --- a/commands/api.js +++ b/commands/api.js @@ -13,6 +13,7 @@ import devtools from '../lib/devtools.js'; import * as acorn from "acorn"; import fs from "fs"; import cors from "cors"; +import { base_host } from "../client/config.js"; import { createHttpTerminator } from 'http-terminator'; const app = express(); @@ -96,6 +97,21 @@ export const main = async (opts) => { if(opts.DANGER_ADMIN) { const { media_servers } = await import("../lib/config.js"); app.use(cors({origin: media_servers})); + + // this is necessary to deal with Node 18 defaulting to IPv6 for "localhost" + app.use((req, res, next) => { + const full_host = `${req.protocol}://${req.get('host')}`; + + if(full_host !== base_host) { + const redirect_to = new URL(req.url, base_host); + + log.error(`Your client/config.js:base_host is ${base_host} but you are accessing the site at ${full_host}. Redirecting to ${redirect_to} so cookies will function!`); + + res.redirect(redirect_to); + } else { + next(); + } + }) } if(opts.debugHeaders) {