Skip to content

Commit 25c2130

Browse files
authored
Merge pull request #6321 from alphagov/run-locally-default
Only listen for local connections by default
2 parents 2eb3682 + 0c54655 commit 25c2130

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

docs/contributing/running-locally.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ This will build sources, serve pages and watch for changes.
4242
npm start
4343
```
4444

45+
By default, the local server will only accept connections from the same machine. If you need to allow external connections, for example if you want to test from another device, you'll need to set the `ALLOW_EXTERNAL_CONNECTIONS` environment variable to `true`:
46+
47+
```shell
48+
ALLOW_EXTERNAL_CONNECTIONS=true npm start
49+
```
50+
4551
## Deploying
4652

4753
You can deploy your project straight to a Heroku instance.

jest-dev-server.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const { ports } = require('@govuk-frontend/config')
55
*/
66
module.exports = {
77
command: 'npm start --workspace @govuk-frontend/review',
8+
9+
host: 'localhost',
10+
811
port: ports.app,
912

1013
// Allow 30 seconds to start server

packages/govuk-frontend-review/browsersync.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ const frontendPath = packageTypeToPath('govuk-frontend', {
1818
module.exports = {
1919
proxy: urls.app,
2020

21+
// Bind to localhost only by default
22+
...(process.env.ALLOW_EXTERNAL_CONNECTIONS === 'true'
23+
? {}
24+
: { listen: 'localhost' }),
25+
2126
// Prevent browser mirroring
2227
ghostMode: false,
2328

packages/govuk-frontend-review/src/start.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ import app from './app.mjs'
44

55
const server = await app()
66

7-
server.listen(ports.app)
7+
server.listen({
8+
host: 'localhost',
9+
port: ports.app
10+
})

0 commit comments

Comments
 (0)