Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart server when any code in server modified. #964

Closed
BanDroid opened this issue Jun 19, 2023 · 9 comments
Closed

Restart server when any code in server modified. #964

BanDroid opened this issue Jun 19, 2023 · 9 comments
Labels
enhancement ✨ New feature or request

Comments

@BanDroid
Copy link
Contributor

Description

i found this problem when modifying /server/index.js and adding some middleware. i had to close the server and run it again manually to be able seeing the changes.

i hope the boilerplate could use nodemon to watch the changes in server directory.

@BanDroid BanDroid added the enhancement ✨ New feature or request label Jun 19, 2023
@brillout
Copy link
Member

See the comment on top of the server file:

// This file isn't processed by Vite, see #562

Please respect https://brillout.github.io/rules/. Thanks!

@brillout brillout closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2023
@brillout
Copy link
Member

Please respect https://brillout.github.io/rules/. Thanks!

That said, feel free to reach out if you believe it's related to VPS. And, actually, turns out this conversation is actually constructive: 65b5b1b. So thanks for reaching out.

@BanDroid
Copy link
Contributor Author

BanDroid commented Jun 19, 2023

boilerplates still use node which not watching any changes and have to manually restart the server.

@BanDroid
Copy link
Contributor Author

i've tried using nodemon (^2.0.22) now, it does work great in react-js javascript boilerplate. i changed the server script in package.json to be like this:

"server": "nodemon ./server/index.js -w ./server"

@royalswe
Copy link
Contributor

royalswe commented Jun 19, 2023

That said, feel free to reach out if you believe it's related to VPS. And, actually, turns out this conversation is actually constructive: 65b5b1b. So thanks for reaching out.

You could just add this line in package.json
"server:watch": "nodemon server -e ts,json --exec 'npm run server'",

complete scripts

  "scripts": {
    "dev": "npm run server:watch",
    "prod": "npm run build && npm run server:prod",
    "build": "vite build",
    "server": "ts-node ./server/index.ts",
    "server:watch": "nodemon server -e ts,json --exec 'npm run server'",
    "server:prod": "cross-env NODE_ENV=production ts-node ./server/index.ts"
  },

and off course you need to have nodemon installed globally or add it as dependencies.

@brillout
Copy link
Member

Correct me if I'm wrong, but I think the problem with that is that it would restart the server even when a Vite file is being HMR'd.

@BanDroid
Copy link
Contributor Author

Correct me if I'm wrong, but I think the problem with that is that it would restart the server even when a Vite file is being HMR'd.

my script command does fine, only watching in server directory. anyway, any reason you dont want to use nodemon in boilerplate? if you dont want to do it, i could help you with that to save you some time

@royalswe
Copy link
Contributor

royalswe commented Jun 19, 2023

Both my and BanDroid's example restarts the server when vite.config is changed.

@brillout
Copy link
Member

The problem with that then is that it won't watch dependencies outside of server/. Let's follow #562 (comment) instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants