Skip to content

Commit

Permalink
express listens only if not running through vite
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Jan 21, 2025
1 parent 58f3f02 commit 2616e16
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 8 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
})

Check failure on line 48 in src/server.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
} else {
console.log("Grout is running through port managed by Vite");
}

export const viteNodeApp = app;
5 changes: 4 additions & 1 deletion vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ export default defineConfig({
initAppOnBoot: true,
outputFormat: "esm"
})
]
],
server: {
port: 5000
}
});

0 comments on commit 2616e16

Please sign in to comment.