forked from swagger-api/swagger-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
58 lines (47 loc) · 1.41 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');
var open = require('open');
var IP = '127.0.0.1';
var argv = require('minimist')(process.argv.slice(2));
/**
* Start the server with webpack config
*
* @param {number} port - TCP port
* @param {function} cb - Error first success callback
*/
function startServer(port, cb) {
config.entry.app.unshift('webpack-dev-server/client?http://' + IP + ':' + port + '/');
var compiler = webpack(config);
var server = new WebpackDevServer(compiler, {
progress: true,
stats: 'errors-only',
showModules: false,
publicPath: '/' + config.output.publicPath,
headers: {
'Set-Cookie':
'swagger-editor-development-mode:' +
(argv.production ? 'false' : 'true') + ';'
}
});
server.listen(port, IP, cb);
}
// if this file was triggered directly, launch the server
if (require.main === module) {
var PORT = process.env.PORT || 8080;
startServer(PORT, function(err) {
if (err) {
return console.log(err);
}
var url = 'http://' + IP + ':' + PORT;
console.log('Development server started at', url);
// to avoid opening the browser set DO_NOT_OPEN environment
// variable to true
if (!process.env.DO_NOT_OPEN) {
console.log('Opening the browser');
open(url);
}
});
}
module.exports = startServer;