Coalesce quota refreshes and consolidate shared helpers
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
This commit is contained in:
parent
a4cf633ab4
commit
748415082b
19 changed files with 216 additions and 64 deletions
22
server.mjs
22
server.mjs
|
|
@ -1,5 +1,6 @@
|
|||
// Rôle : sert l'application Vite construite ou les sources publiques en local.
|
||||
import { createReadStream, existsSync, readFileSync, statSync } from "node:fs";
|
||||
import { createReadStream, existsSync, statSync } from "node:fs";
|
||||
import { loadProjectEnv } from "./scripts/load-project-env.mjs";
|
||||
import { createServer } from "node:http";
|
||||
import { extname, join, relative, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
|
@ -10,24 +11,7 @@ const distRoot = join(websiteRoot, "dist");
|
|||
const root = existsSync(distRoot) ? distRoot : websiteRoot;
|
||||
const publicRoot = existsSync(distRoot) ? distRoot : join(websiteRoot, "public");
|
||||
|
||||
function loadEnvFile(file = ".env") {
|
||||
if (!existsSync(file)) return;
|
||||
|
||||
const lines = readFileSync(file, "utf8").split(/\r?\n/);
|
||||
lines.forEach((line) => {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed || trimmed.startsWith("#")) return;
|
||||
|
||||
const separatorIndex = trimmed.indexOf("=");
|
||||
if (separatorIndex < 1) return;
|
||||
|
||||
const key = trimmed.slice(0, separatorIndex).trim();
|
||||
const value = trimmed.slice(separatorIndex + 1).trim().replace(/^["']|["']$/g, "");
|
||||
if (!process.env[key]) process.env[key] = value;
|
||||
});
|
||||
}
|
||||
|
||||
loadEnvFile();
|
||||
loadProjectEnv();
|
||||
|
||||
const port = Number(process.env.PORT || 5173);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue