-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This listener which looks out for file changes using BrowserSync doesn't need to be part of `server.js` as it's only needed for npm start. We added a new file called `listen-on-port.js` - this needs to be separate from `server.js` for Jest to work correctly. More detail here: http://www.albertgao.xyz/2017/05/24/how-to-test-expressjs-with-jest-and-supertest/#2-Separate-your-app-and-sever
- Loading branch information
1 parent
fb0c8e3
commit 0ccbc4a
Showing
3 changed files
with
48 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
// NPM dependencies | ||
const browserSync = require('browser-sync') | ||
|
||
// Local dependencies | ||
const server = require('./server.js') | ||
const config = require('./app/config.js') | ||
const utils = require('./lib/utils.js') | ||
|
||
// Set up configuration variables | ||
var useBrowserSync = config.useBrowserSync.toLowerCase() | ||
var env = (process.env.NODE_ENV || 'development').toLowerCase() | ||
|
||
utils.findAvailablePort(server, function (port) { | ||
console.log('Listening on port ' + port + ' url: http://localhost:' + port) | ||
if (env === 'production' || useBrowserSync === 'false') { | ||
server.listen(port) | ||
} else { | ||
server.listen(port - 50, function () { | ||
browserSync({ | ||
proxy: 'localhost:' + (port - 50), | ||
port: port, | ||
ui: false, | ||
files: ['public/**/*.*', 'app/views/**/*.*'], | ||
ghostmode: false, | ||
open: false, | ||
notify: false, | ||
logLevel: 'error' | ||
}) | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters