Some checks failed
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Admin Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Codespell / Check for spelling errors (push) Has been cancelled
Sync Repositories / sync_changes (push) Has been cancelled
Synced from upstream: 8853637e981ed7d8a6cff32bd98e7afe20f54362
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import "react-router";
|
|
import { createRequestHandler } from "@react-router/express";
|
|
import express from "express";
|
|
import type { Express } from "express";
|
|
import { createProxyMiddleware } from "http-proxy-middleware";
|
|
|
|
const NEXT_PUBLIC_API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL
|
|
? process.env.NEXT_PUBLIC_API_BASE_URL.replace(/\/$/, "")
|
|
: "http://127.0.0.1:8000";
|
|
const NEXT_PUBLIC_API_BASE_PATH = process.env.NEXT_PUBLIC_API_BASE_PATH
|
|
? process.env.NEXT_PUBLIC_API_BASE_PATH.replace(/\/+$/, "")
|
|
: "/api";
|
|
const NORMALIZED_API_BASE_PATH = NEXT_PUBLIC_API_BASE_PATH.startsWith("/")
|
|
? NEXT_PUBLIC_API_BASE_PATH
|
|
: `/${NEXT_PUBLIC_API_BASE_PATH}`;
|
|
const NEXT_PUBLIC_ADMIN_BASE_PATH = process.env.NEXT_PUBLIC_ADMIN_BASE_PATH
|
|
? process.env.NEXT_PUBLIC_ADMIN_BASE_PATH.replace(/\/$/, "")
|
|
: "/";
|
|
|
|
export const app: Express = express();
|
|
|
|
// Ensure proxy-aware hostname/URL handling (e.g., X-Forwarded-Host/Proto)
|
|
// so generated URLs/redirects reflect the public host when behind Nginx.
|
|
// See related fix in Remix Express adapter.
|
|
app.set("trust proxy", true);
|
|
|
|
app.use(
|
|
"/api",
|
|
createProxyMiddleware({
|
|
target: NEXT_PUBLIC_API_BASE_URL,
|
|
changeOrigin: true,
|
|
secure: false,
|
|
pathRewrite: (path: string) =>
|
|
NORMALIZED_API_BASE_PATH === "/api" ? path : path.replace(/^\/api/, NORMALIZED_API_BASE_PATH),
|
|
})
|
|
);
|
|
|
|
const router = express.Router();
|
|
|
|
router.use(
|
|
createRequestHandler({
|
|
build: () => import("virtual:react-router/server-build"),
|
|
})
|
|
);
|
|
|
|
app.use(NEXT_PUBLIC_ADMIN_BASE_PATH, router);
|