From 2616e16efdeaeb814bd0a21f8c54539038c8b56f Mon Sep 17 00:00:00 2001 From: Emma Date: Tue, 21 Jan 2025 16:32:34 +0000 Subject: [PATCH] express listens only if not running through vite --- README.md | 5 +++-- src/server.ts | 11 ++++++++--- vite.config.mts | 5 ++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e436856..dc03405 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,14 @@ Grout is implemented as an [express](https://expressjs.com/) server in Typescrip Developed with node v22. -Run in dev mode with hot reloading: `npm run dev` +Run in dev mode with hot reloading managed by vite: `npm run dev` Build for production: `npm run build` Run in production mode: `npm run prod` -In both modes, local run is on port 5000. Port is configured in `config/grout.config.json` +In both modes, local run is on port 5000. Port is configured in `config/grout.config.json` (for running in production) +and `vite.config.mts` (for running in dev mode). ## Tests diff --git a/src/server.ts b/src/server.ts index 57824cd..0afb474 100644 --- a/src/server.ts +++ b/src/server.ts @@ -41,8 +41,13 @@ Object.freeze(app.locals); // We don't expect anything else to modify app.locals app.use("/", registerRoutes()); app.use(handleError); -app.listen(port, () => { - console.log(`Grout is running on port ${port}`); -}); + +if (import.meta.env.PROD) { + app.listen(port, () => { + console.log(`Grout is running on port ${port}`); + }) +} else { + console.log("Grout is running through port managed by Vite"); +} export const viteNodeApp = app; diff --git a/vite.config.mts b/vite.config.mts index eeeadf1..4f10bdb 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -15,5 +15,8 @@ export default defineConfig({ initAppOnBoot: true, outputFormat: "esm" }) - ] + ], + server: { + port: 5000 + } });