Skip to content

Commit 05817ae

Browse files
Add browser-sync (#97)
This adds browser-sync in development mode only, copied across from the existing prototype kit. Fixes #77
1 parent d6162d0 commit 05817ae

File tree

3 files changed

+1275
-28
lines changed

3 files changed

+1275
-28
lines changed

lib/index.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const { join } = require('node:path')
22

3+
const browserSync = require('browser-sync')
4+
const { createProxyMiddleware } = require('http-proxy-middleware')
5+
36
const build = require('./build')
47
const expressMiddleware = require('./express-middleware')
58
const expressSettings = require('./express-settings')
@@ -79,7 +82,29 @@ NHSPrototypeKit.prototype.start = async function (port) {
7982
if (nodeEnv === 'production') {
8083
console.info(`Running on port ${availablePort}`)
8184
} else {
82-
console.info(`Running at http://localhost:${availablePort}/`)
85+
const bs = browserSync.create()
86+
87+
bs.init({
88+
port: availablePort,
89+
files: ['views/**/*.*', 'assets/**/*.*'],
90+
91+
// We create our own proxy middleware here
92+
// as the default proxy option does not work
93+
// on GitHub Codespaces.
94+
middleware: createProxyMiddleware({
95+
changeOrigin: true,
96+
target: `http://localhost:${availablePort}`
97+
}),
98+
server: {
99+
baseDir: join(__dirname, 'public')
100+
},
101+
102+
ghostMode: false,
103+
open: false,
104+
notify: true,
105+
watch: true,
106+
ui: false
107+
})
83108
}
84109
})
85110
}

0 commit comments

Comments
 (0)