diff --git a/netlify.toml b/netlify.toml index 9b41f55..6cb261d 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,12 +1,8 @@ -[build] - publish = "public" - [functions] - external_node_modules = ["express"] + directory = "netlify/functions" + external_node_modules = ["express", "mongoose", "ejs"] node_bundler = "esbuild" [[redirects]] - from = "/*" + from = "/api/*" to = "/.netlify/functions/api/:splat" - status = 200 - force = true \ No newline at end of file diff --git a/netlify/functions/api.js b/netlify/functions/api.js index ab110dd..b74ebc1 100644 --- a/netlify/functions/api.js +++ b/netlify/functions/api.js @@ -1,5 +1,4 @@ import serverless from "serverless-http"; +import { app } from "../../server.js"; -const serverModule = await import("../../server.js"); - -export const handler = serverless(serverModule.app); +export const handler = serverless(app); diff --git a/netlify/functions/chaos.js b/netlify/functions/chaos.js new file mode 100644 index 0000000..d6fed59 --- /dev/null +++ b/netlify/functions/chaos.js @@ -0,0 +1,3 @@ +export const handler = async () => { + return { statusCode: 200, body: "deployment chaos on netlify" }; +}; diff --git a/package-lock.json b/package-lock.json index 3f3ba40..7e4067f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,8 +24,7 @@ "nodemon": "^3.1.10", "tsx": "^4.20.3", "typescript": "~5.8.3", - "undici-types": "^7.12.0", - "vite": "^7.0.4" + "undici-types": "^7.12.0" } }, "node_modules/@babel/code-frame": { @@ -998,12 +997,12 @@ "cpu": [ "arm" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "android" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-android-arm64": { "version": "4.45.1", @@ -1012,12 +1011,12 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "android" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-darwin-arm64": { "version": "4.45.1", @@ -1026,12 +1025,12 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "darwin" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-darwin-x64": { "version": "4.45.1", @@ -1040,12 +1039,12 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "darwin" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-freebsd-arm64": { "version": "4.45.1", @@ -1054,12 +1053,12 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "freebsd" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-freebsd-x64": { "version": "4.45.1", @@ -1068,12 +1067,12 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "freebsd" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { "version": "4.45.1", @@ -1082,12 +1081,12 @@ "cpu": [ "arm" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { "version": "4.45.1", @@ -1096,12 +1095,12 @@ "cpu": [ "arm" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-arm64-gnu": { "version": "4.45.1", @@ -1110,12 +1109,12 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-arm64-musl": { "version": "4.45.1", @@ -1124,12 +1123,12 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-loongarch64-gnu": { "version": "4.45.1", @@ -1138,12 +1137,12 @@ "cpu": [ "loong64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { "version": "4.45.1", @@ -1152,12 +1151,12 @@ "cpu": [ "ppc64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { "version": "4.45.1", @@ -1166,12 +1165,12 @@ "cpu": [ "riscv64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-riscv64-musl": { "version": "4.45.1", @@ -1180,12 +1179,12 @@ "cpu": [ "riscv64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-s390x-gnu": { "version": "4.45.1", @@ -1194,12 +1193,12 @@ "cpu": [ "s390x" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-x64-gnu": { "version": "4.45.1", @@ -1208,12 +1207,12 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-x64-musl": { "version": "4.45.1", @@ -1222,12 +1221,12 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-win32-arm64-msvc": { "version": "4.45.1", @@ -1236,12 +1235,12 @@ "cpu": [ "arm64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "win32" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-win32-ia32-msvc": { "version": "4.45.1", @@ -1250,12 +1249,12 @@ "cpu": [ "ia32" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "win32" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-win32-x64-msvc": { "version": "4.45.1", @@ -1264,12 +1263,12 @@ "cpu": [ "x64" ], - "dev": true, "license": "MIT", "optional": true, "os": [ "win32" - ] + ], + "peer": true }, "node_modules/@so-ric/colorspace": { "version": "1.1.6", @@ -3185,21 +3184,6 @@ "pend": "~1.2.0" } }, - "node_modules/fdir": { - "version": "6.4.6", - "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.4.6.tgz", - "integrity": "sha512-hiFoqpyZcfNm1yc4u8oWCf9A2c4D3QjCrks3zmoVKVxpQRzmPNar1hUJcBG2RQHvEVGDN+Jm81ZheVLAQMK6+w==", - "dev": true, - "license": "MIT", - "peerDependencies": { - "picomatch": "^3 || ^4" - }, - "peerDependenciesMeta": { - "picomatch": { - "optional": true - } - } - }, "node_modules/fecha": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz", @@ -3356,7 +3340,6 @@ "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, "hasInstallScript": true, "license": "MIT", "optional": true, @@ -5216,8 +5199,9 @@ "version": "4.45.1", "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.45.1.tgz", "integrity": "sha512-4iya7Jb76fVpQyLoiVpzUrsjQ12r3dM7fIVz+4NwoYvZOShknRmiv+iu9CClZml5ZLGb0XMcYLutK6w9tgxHDw==", - "devOptional": true, "license": "MIT", + "optional": true, + "peer": true, "dependencies": { "@types/estree": "1.0.8" }, @@ -5776,23 +5760,6 @@ "integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==", "license": "MIT" }, - "node_modules/tinyglobby": { - "version": "0.2.14", - "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.14.tgz", - "integrity": "sha512-tX5e7OM1HnYr2+a2C/4V0htOcSQcoSTH9KgJnVvNm5zm/cyEWKJ7j7YutsH9CxMdtOkkLFy2AHrMci9IM8IPZQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "fdir": "^6.4.4", - "picomatch": "^4.0.2" - }, - "engines": { - "node": ">=12.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/SuperchupuDev" - } - }, "node_modules/tmp": { "version": "0.2.5", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.5.tgz", @@ -6108,81 +6075,6 @@ "node": ">= 0.8" } }, - "node_modules/vite": { - "version": "7.0.6", - "resolved": "https://registry.npmjs.org/vite/-/vite-7.0.6.tgz", - "integrity": "sha512-MHFiOENNBd+Bd9uvc8GEsIzdkn1JxMmEeYX35tI3fv0sJBUTfW5tQsoaOwuY4KhBI09A3dUJ/DXf2yxPVPUceg==", - "dev": true, - "license": "MIT", - "dependencies": { - "esbuild": "^0.25.0", - "fdir": "^6.4.6", - "picomatch": "^4.0.3", - "postcss": "^8.5.6", - "rollup": "^4.40.0", - "tinyglobby": "^0.2.14" - }, - "bin": { - "vite": "bin/vite.js" - }, - "engines": { - "node": "^20.19.0 || >=22.12.0" - }, - "funding": { - "url": "https://github.com/vitejs/vite?sponsor=1" - }, - "optionalDependencies": { - "fsevents": "~2.3.3" - }, - "peerDependencies": { - "@types/node": "^20.19.0 || >=22.12.0", - "jiti": ">=1.21.0", - "less": "^4.0.0", - "lightningcss": "^1.21.0", - "sass": "^1.70.0", - "sass-embedded": "^1.70.0", - "stylus": ">=0.54.8", - "sugarss": "^5.0.0", - "terser": "^5.16.0", - "tsx": "^4.8.1", - "yaml": "^2.4.2" - }, - "peerDependenciesMeta": { - "@types/node": { - "optional": true - }, - "jiti": { - "optional": true - }, - "less": { - "optional": true - }, - "lightningcss": { - "optional": true - }, - "sass": { - "optional": true - }, - "sass-embedded": { - "optional": true - }, - "stylus": { - "optional": true - }, - "sugarss": { - "optional": true - }, - "terser": { - "optional": true - }, - "tsx": { - "optional": true - }, - "yaml": { - "optional": true - } - } - }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", diff --git a/package.json b/package.json index 736d93b..d0705d0 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,7 @@ "type": "module", "keywords": [], "scripts": { - "dev": "vite", - "build": "echo 'Build complete'", + "build": "node -e \"console.log('build ok')\"", "start": "node server.js", "server": "nodemon --watch './' --ext ts,js --exec 'tsx' server.js", "macStart": "nodemon --watch './' --ext ts --exec 'node --loader ts-node/esm' server.js", @@ -21,8 +20,7 @@ "nodemon": "^3.1.10", "tsx": "^4.20.3", "typescript": "~5.8.3", - "undici-types": "^7.12.0", - "vite": "^7.0.4" + "undici-types": "^7.12.0" }, "dependencies": { "@netlify/functions": "^4.2.7", diff --git a/server.js b/server.js index 9689eb9..6187d7c 100644 --- a/server.js +++ b/server.js @@ -6,15 +6,20 @@ import dotenv from "dotenv"; dotenv.config(); -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); +// const __filename = fileURLToPath(import.meta.url); +// const __dirname = path.dirname(__filename); export const app = express(); + +const ROOT = process.cwd(); + app.set("view engine", "ejs"); -app.set("views", path.join(__dirname, "views")); -app.use(express.static("public")); -app.use("/managers", express.static(path.join(__dirname, "managers"))); +app.set("views", path.join(ROOT, "views")); +app.use(express.static(path.join(ROOT, "public"))); +app.use("/managers", express.static(path.join(ROOT, "managers"))); app.use(express.json()); +// app.set("views", path.join(__dirname, "views")); +// app.use("/managers", express.static(path.join(__dirname, "managers"))); /** * Logs all incoming requests for debugging purposes @@ -27,11 +32,32 @@ app.use((req, _, next) => { next(); }); -mongoose.connect(process.env.MONGODB_URI); +// mongoose.connect(process.env.MONGODB_URI); +let mongoReady = false; +async function ensureMongo() { + if (mongoReady && mongoose.connection.readyState === 1) return; + if (!process.env.MONGODB_URI) { + console.warn("Mongo keys are missing"); + return; + } + await mongoose.connect(process.env.MONGODB_URI); + mongoReady = true; + console.log("Mongo connected"); + console.log("Database of madness has started!"); +} + +app.use(async (_req, _res, next) => { + try { + await ensureMongo(); + next(); + } catch (error) { + next(error); + } +}); -const db = mongoose.connection; -db.on("error", (error) => console.log(error)); -db.once("open", () => console.log("Database of madness has started!")); +// const db = mongoose.connection; +// db.on("error", (error) => console.log(error)); +// db.once("open", () => console.log("Database of madness has started!")); import abilitiesRouter from "./routes/routerAbilities.js"; app.use("/abilities", abilitiesRouter); diff --git a/vite.config.js b/vite.config.js deleted file mode 100644 index 6fac2df..0000000 --- a/vite.config.js +++ /dev/null @@ -1,19 +0,0 @@ -import { defineConfig } from "vite"; - -export default defineConfig({ - root: "./public", - server: { - port: 5173, - proxy: { - // Proxy API calls to the express server - "/api": { - target: "http://localhost:3001", - changeOrigin: true, - }, - }, - }, - build: { - outDir: "../dist", - emptyOutDir: true, - }, -});