x
This commit is contained in:
1 parent
927f03a8b7
commit
4c38f2a596
5 files changed
+83
-6
No files matched your search
@@ -30,6 +30,27 @@ import { mediaRoute } from "./routes/media";
|
||||
const PORT = process.env.PORT ? parseInt(process.env.PORT) : 3051;
|
||||
const CORS_ORIGIN = process.env.CORS_ORIGIN || "http://localhost:5173";
|
||||
const JWT_SECRET = process.env.JWT_SECRET || "homaroma_secret_2026_scent";
|
||||
const isDevelopment = process.env.NODE_ENV !== "production";
|
||||
const isPrivateLanHostname = (hostname) => {
|
||||
return (hostname === "localhost" ||
|
||||
hostname === "127.0.0.1" ||
|
||||
hostname === "0.0.0.0" ||
|
||||
hostname === "::1" ||
|
||||
/^10\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname) ||
|
||||
/^192\.168\.\d{1,3}\.\d{1,3}$/.test(hostname) ||
|
||||
/^172\.(1[6-9]|2\d|3[0-1])\.\d{1,3}\.\d{1,3}$/.test(hostname));
|
||||
};
|
||||
const allowLanDevOrigin = (request) => {
|
||||
const origin = request.headers.get("origin");
|
||||
if (!origin)
|
||||
return false;
|
||||
try {
|
||||
return isPrivateLanHostname(new URL(origin).hostname);
|
||||
}
|
||||
catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
const app = new Elysia()
|
||||
.onParse(async ({ request }) => {
|
||||
console.log('[onParse] Incoming request URL:', request.url);
|
||||
@@ -39,9 +60,10 @@ const app = new Elysia()
|
||||
return text;
|
||||
}
|
||||
})
|
||||
.use(cors({
|
||||
.use(cors({
|
||||
origin: [
|
||||
...CORS_ORIGIN.split(",").map((o) => o.trim()),
|
||||
...(isDevelopment ? [allowLanDevOrigin] : []),
|
||||
"https://admin.homaroma.shop",
|
||||
"https://spa.homaroma.shop", // LIFF (SPA)
|
||||
"https://homaroma.shop", // Main Website
|
||||
@@ -96,4 +118,4 @@ const app = new Elysia()
|
||||
.listen({ port: PORT, hostname: "0.0.0.0" });
|
||||
console.log(`🌿 HomAroma API is running at http://${app.server?.hostname}:${app.server?.port}`);
|
||||
console.log(`📖 Swagger docs: http://${app.server?.hostname}:${app.server?.port}/swagger`);
|
||||
//# sourceMappingURL=index.js.map
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -30,6 +30,30 @@ import { mediaRoute } from "./routes/media";
|
||||
const PORT = process.env.PORT ? parseInt(process.env.PORT) : 3051;
|
||||
const CORS_ORIGIN = process.env.CORS_ORIGIN || "http://localhost:5173";
|
||||
const JWT_SECRET = process.env.JWT_SECRET || "homaroma_secret_2026_scent";
|
||||
const isDevelopment = process.env.NODE_ENV !== "production";
|
||||
|
||||
const isPrivateLanHostname = (hostname: string) => {
|
||||
return (
|
||||
hostname === "localhost" ||
|
||||
hostname === "127.0.0.1" ||
|
||||
hostname === "0.0.0.0" ||
|
||||
hostname === "::1" ||
|
||||
/^10\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname) ||
|
||||
/^192\.168\.\d{1,3}\.\d{1,3}$/.test(hostname) ||
|
||||
/^172\.(1[6-9]|2\d|3[0-1])\.\d{1,3}\.\d{1,3}$/.test(hostname)
|
||||
);
|
||||
};
|
||||
|
||||
const allowLanDevOrigin = (request: Request) => {
|
||||
const origin = request.headers.get("origin");
|
||||
if (!origin) return false;
|
||||
|
||||
try {
|
||||
return isPrivateLanHostname(new URL(origin).hostname);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const app = new Elysia()
|
||||
.onParse(async ({ request }) => {
|
||||
@@ -44,6 +68,7 @@ const app = new Elysia()
|
||||
cors({
|
||||
origin: [
|
||||
...CORS_ORIGIN.split(",").map((o) => o.trim()),
|
||||
...(isDevelopment ? [allowLanDevOrigin] : []),
|
||||
"https://admin.homaroma.shop",
|
||||
"https://spa.homaroma.shop", // LIFF (SPA)
|
||||
"https://homaroma.shop", // Main Website
|
||||
|
||||
Reference in new issue
Block a user