Skip to content

Commit

Permalink
Automatically reload the server when it changes (badges#3401)
Browse files Browse the repository at this point in the history
While working on badges#2428 I found myself wanting to reload the server frequently. This is working great and reducing my iteration time significantly. I should have tackled this way sooner! 🙊 

I’ve left `verbose` on which seems useful, at least in the short term while we’re tuning the configuration.

Close badges#2426
  • Loading branch information
paulmelnikow authored May 1, 2019
1 parent 26852ee commit 73ed777
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: node server
web: npm run start:server:prod
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,15 @@ You can read a [tutorial on how to add a badge][tutorial].
Tests need to pass in Node 8 and 10.
2. Clone this repository.
3. Run `npm ci` to install the dependencies.
4. Run `npm start` to start the server.
4. Run `npm start` to start the badge server and the frontend dev server.
5. Open `http://localhost:3000/` to view the frontend.

When server source files change, the badge server should automatically restart
itself (using [nodemon][]). When the frontend files change, the frontend dev
server (`gatsby dev`) should also automatically reload. However the badge
definitions are built only before the server first starts. To regenerate those,
either run `npm run defs` or manually restart the server.

To debug a badge from the command line, run `npm run badge -- /npm/v/nock.svg`.
It also works with full URLs like
`npm run badge -- https://img.shields.io/npm/v/nock.svg`.
Expand Down Expand Up @@ -130,6 +136,7 @@ Daily tests, including a full run of the service tests and overall code coverage
[sentry]: https://sentry.io/
[sentry configuration]: doc/self-hosting.md#sentry
[daily-tests]: https://github.com/badges/daily-tests
[nodemon]: https://nodemon.io/

## Hosting your own server

Expand Down
9 changes: 4 additions & 5 deletions doc/TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ install node and npm: https://nodejs.org/en/download/
3. `cd shields`
4. Install project dependencies
`npm ci`
5. Run the server
5. Run the badge server and the frontend dev server
`npm start`
6. Visit the website to check the front-end is loaded:
[http://localhost:3000/](http://localhost:3000/)
Expand Down Expand Up @@ -152,10 +152,9 @@ The process of turning this object into an image is handled automatically by the
To try out this example badge:

1. Copy and paste this code into a new file in `/services/example/example.service.js`
2. Quit the running server with `Control+C`.
3. Start the server again.
`npm start`
4. Visit the badge at <http://localhost:8080/example/foo.svg>.
2. The server should restart on its own. (If it doesn't for some reason, quit
the running server with `Control+C`, then start it again with `npm start`.)
3. Visit the badge at <http://localhost:8080/example/foo.svg>.
It should look like this: ![](https://img.shields.io/badge/example-foo-blue.svg)

[path-to-regexp]: https://github.com/pillarjs/path-to-regexp#parameters
Expand Down
112 changes: 112 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@
"defs": "node scripts/export-service-definitions-cli.js > service-definitions.yml",
"build": "run-s defs features && gatsby build",
"heroku-postbuild": "run-s --silent build",
"start:server": "cross-env NODE_CONFIG_ENV=development node server 8080",
"now-start": "node server",
"start:server:prod": "node server",
"now-start": "npm run start:server:prod",
"start:server:e2e-on-build": "node server 8080",
"start:server": "cross-env NODE_CONFIG_ENV=development nodemon server 8080",
"prestart": "run-s --silent depcheck defs features",
"start": "concurrently --names server,frontend \"npm run start:server\" \"cross-env GATSBY_BASE_URL=http://localhost:8080 gatsby develop --port 3000\"",
"e2e": "start-server-and-test start http://localhost:3000 test:e2e",
"e2e-on-build": "cross-env CYPRESS_baseUrl=http://localhost:8080 start-server-and-test start:server http://localhost:8080 test:e2e",
"e2e-on-build": "cross-env CYPRESS_baseUrl=http://localhost:8080 start-server-and-test start:server:e2e-on-build http://localhost:8080 test:e2e",
"badge": "cross-env NODE_CONFIG_ENV=test TRACE_SERVICES=true node scripts/badge-cli.js"
},
"lint-staged": {
Expand All @@ -122,6 +124,20 @@
"git add"
]
},
"nodemonConfig": {
"verbose": true,
"ext": "js",
"ignore": [
"package.json",
"**/*.spec.js",
"**/*.tester.js",
"**/*.integration.js",
"frontend/",
"public/",
"build/",
"cypress/"
]
},
"devDependencies": {
"@babel/core": "^7.4.3",
"@babel/plugin-proposal-class-properties": "^7.4.0",
Expand Down Expand Up @@ -193,6 +209,7 @@
"nock": "11.0.0-beta.10",
"node-fetch": "^2.3.0",
"node-mocks-http": "^1.7.3",
"nodemon": "^1.18.11",
"npm-run-all": "^4.1.5",
"nyc": "^14.0.0",
"opn-cli": "^4.1.0",
Expand Down

0 comments on commit 73ed777

Please sign in to comment.