Skip to content

Commit

Permalink
Hot reload server
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesGarth committed Jun 29, 2023
1 parent 6fb9ec3 commit c7e8b44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions env.d.ts
@@ -0,0 +1 @@
/// <reference types="vite/client" />
10 changes: 8 additions & 2 deletions index.ts
Expand Up @@ -10,6 +10,12 @@ app.get('/', (req: Request, res: Response) => {
res.send('Hello World!');
});

app.listen(port, () => {
const server = app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
});

if (import.meta.hot) {
import.meta.hot.on("vite:beforeFullReload", () => {
server.close();
});
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.ts",
"scripts": {
"start": "vite-node .",
"start": "vite-node --watch index.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
Expand Down

0 comments on commit c7e8b44

Please sign in to comment.