Skip to content

Commit

Permalink
remove port finder
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Aug 10, 2016
1 parent 43e38d2 commit 722c706
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 182 deletions.
226 changes: 110 additions & 116 deletions dist/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ var _connectBusboy = require('connect-busboy');

var _connectBusboy2 = _interopRequireDefault(_connectBusboy);

var _portfinder = require('portfinder');

var _portfinder2 = _interopRequireDefault(_portfinder);

var _cliColor = require('cli-color');

var _cliColor2 = _interopRequireDefault(_cliColor);
Expand Down Expand Up @@ -87,136 +83,134 @@ var html = _expressSecureHandlebars2.default.create({
}
});

_portfinder2.default.getPort(function (err, freePort) {
var opts = {};
if (_cli.fileUtils.isFile(_cli.fileUtils.concatPath(_cli.config.root, 'cert.pem'))) {
opts = {
key: _fsExtra2.default.readFileSync(_cli.fileUtils.concatPath(_cli.config.root, 'key.pem')),
cert: _fsExtra2.default.readFileSync(_cli.fileUtils.concatPath(_cli.config.root, 'cert.pem'))
};
}
var opts = {};
if (_cli.fileUtils.isFile(_cli.fileUtils.concatPath(_cli.config.root, 'cert.pem'))) {
opts = {
key: _fsExtra2.default.readFileSync(_cli.fileUtils.concatPath(_cli.config.root, 'key.pem')),
cert: _fsExtra2.default.readFileSync(_cli.fileUtils.concatPath(_cli.config.root, 'cert.pem'))
};
}

var app = (0, _express2.default)(opts);
var app = (0, _express2.default)(opts);

app.set('files', _cli.FileParser.getAllFiles());
app.set('config', _cli.config.getConfigByWebsite());
app.set('projectFiles', _cli.FileParser.getProjetFiles());
app.set('files', _cli.FileParser.getAllFiles());
app.set('config', _cli.config.getConfigByWebsite());
app.set('projectFiles', _cli.FileParser.getProjetFiles());

app.use(_bodyParser2.default.json({ limit: '1gb' }));
app.use(_bodyParser2.default.urlencoded({ limit: '1gb', extended: true, parameterLimit: 10000 }));

app.use(function (req, res, next) {
res.locals.nonce = _nodeUuid2.default.v4();
next();
});
app.use(_bodyParser2.default.json({ limit: '1gb' }));
app.use(_bodyParser2.default.urlencoded({ limit: '1gb', extended: true, parameterLimit: 10000 }));

app.use(function (req, res, next) {
if (typeof req.query.logs !== 'undefined' && req.query.logs !== null && req.query.logs === 'true') {
_cli.config.logs = true;
} else if (typeof req.query.logs !== 'undefined' && req.query.logs !== null && req.query.logs === 'false') {
_cli.config.logs = false;
}
next();
});
app.use(function (req, res, next) {
res.locals.nonce = _nodeUuid2.default.v4();
next();
});

if (_cli.config.security === true) {
app.use((0, _helmet2.default)());
app.use(_helmet2.default.csp({
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'"].concat(_cli.config.csp.scriptSrc),
styleSrc: ["'self'", "'unsafe-inline'"].concat(_cli.config.csp.styleSrc),
imgSrc: ["'self'", 'data:'].concat(_cli.config.csp.imgSrc),
// frameSrc: ["'self'"],
childSrc: ["'self'"].concat(_cli.config.csp.childSrc),
frameAncestors: ["'self'"].concat(_cli.config.csp.frameAncestors),
mediaSrc: ["'self'"].concat(_cli.config.csp.mediaSrc),
fontSrc: ["'self'"].concat(_cli.config.csp.fontSrc),
connectSrc: ["'self'"].concat(_cli.config.csp.connectSrc),
sandbox: ['allow-same-origin', 'allow-scripts', "allow-modals", 'allow-popups', 'allow-forms'],
reportUri: '/report-violation',
objectSrc: [] },
// An empty array allows nothing through
reportOnly: false, // Set to true if you only want browsers to report errors, not block them
setAllHeaders: false, // Set to true if you want to blindly set all headers: Content-Security-Policy, X-WebKit-CSP, and X-Content-Security-Policy.
disableAndroid: false, // Set to true if you want to disable CSP on Android where it can be buggy.
browserSniff: true // Set to false if you want to completely disable any user-agent sniffing. This may make the headers less compatible but it will be much faster. This defaults to `true`.
}));
app.use(function (req, res, next) {
if (typeof req.query.logs !== 'undefined' && req.query.logs !== null && req.query.logs === 'true') {
_cli.config.logs = true;
} else if (typeof req.query.logs !== 'undefined' && req.query.logs !== null && req.query.logs === 'false') {
_cli.config.logs = false;
}
next();
});

var port = abePort !== null ? abePort : freePort || 3000;
port = _cli.Hooks.instance.trigger('beforeExpress', port);
if (_cli.config.security === true) {
app.use((0, _helmet2.default)());
app.use(_helmet2.default.csp({
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'"].concat(_cli.config.csp.scriptSrc),
styleSrc: ["'self'", "'unsafe-inline'"].concat(_cli.config.csp.styleSrc),
imgSrc: ["'self'", 'data:'].concat(_cli.config.csp.imgSrc),
// frameSrc: ["'self'"],
childSrc: ["'self'"].concat(_cli.config.csp.childSrc),
frameAncestors: ["'self'"].concat(_cli.config.csp.frameAncestors),
mediaSrc: ["'self'"].concat(_cli.config.csp.mediaSrc),
fontSrc: ["'self'"].concat(_cli.config.csp.fontSrc),
connectSrc: ["'self'"].concat(_cli.config.csp.connectSrc),
sandbox: ['allow-same-origin', 'allow-scripts', "allow-modals", 'allow-popups', 'allow-forms'],
reportUri: '/report-violation',
objectSrc: [] },
// An empty array allows nothing through
reportOnly: false, // Set to true if you only want browsers to report errors, not block them
setAllHeaders: false, // Set to true if you want to blindly set all headers: Content-Security-Policy, X-WebKit-CSP, and X-Content-Security-Policy.
disableAndroid: false, // Set to true if you want to disable CSP on Android where it can be buggy.
browserSniff: true // Set to false if you want to completely disable any user-agent sniffing. This may make the headers less compatible but it will be much faster. This defaults to `true`.
}));
}

app.set('views', _path2.default.join(__dirname, '/templates'));
app.engine('.html', html.engine);
app.set('view engine', '.html');
var port = abePort !== null ? abePort : 3000;
port = _cli.Hooks.instance.trigger('beforeExpress', port);

app.locals.layout = false;
app.set('views', _path2.default.join(__dirname, '/templates'));
app.engine('.html', html.engine);
app.set('view engine', '.html');

app.use(_middlewares.middleWebsite);
app.use(_express2.default.static(__dirname + '/public'));
app.locals.layout = false;

_cli.FileParser.copySiteAssets();
app.use(_middlewares.middleWebsite);
app.use(_express2.default.static(__dirname + '/public'));

var sites = _cli.FileParser.getFolders(_cli.config.root.replace(/\/$/, ""), false, 0);
_cli.FileParser.copySiteAssets();

var publish = _cli.fileUtils.concatPath(_cli.config.root, _cli.config.publish.url);
app.use(_express2.default.static(publish));
// app.use(express.static(publish))
var sites = _cli.FileParser.getFolders(_cli.config.root.replace(/\/$/, ""), false, 0);

if (_cli.config.partials !== '') {
if (_cli.fileUtils.isFile(_cli.fileUtils.concatPath(_cli.config.root, _cli.config.partials))) {
app.use(_express2.default.static(_cli.fileUtils.concatPath(_cli.config.root, _cli.config.partials)));
}
}
var publish = _cli.fileUtils.concatPath(_cli.config.root, _cli.config.publish.url);
app.use(_express2.default.static(publish));
// app.use(express.static(publish))

if (_cli.config.custom !== '') {
if (_cli.fileUtils.isFile(_cli.fileUtils.concatPath(_cli.config.root, _cli.config.custom))) {
app.use(_express2.default.static(_cli.fileUtils.concatPath(_cli.config.root, _cli.config.custom)));
}
if (_cli.config.partials !== '') {
if (_cli.fileUtils.isFile(_cli.fileUtils.concatPath(_cli.config.root, _cli.config.partials))) {
app.use(_express2.default.static(_cli.fileUtils.concatPath(_cli.config.root, _cli.config.partials)));
}
}

var pluginsPartials = _cli.Plugins.instance.getPartials();
Array.prototype.forEach.call(pluginsPartials, function (pluginPartials) {
app.use(_express2.default.static(pluginPartials));
});
if (_cli.config.custom !== '') {
if (_cli.fileUtils.isFile(_cli.fileUtils.concatPath(_cli.config.root, _cli.config.custom))) {
app.use(_express2.default.static(_cli.fileUtils.concatPath(_cli.config.root, _cli.config.custom)));
}
}

app.use(_express2.default.static(__dirname + '/node_modules/handlebars/dist'));
app.use((0, _connectBusboy2.default)({
limits: {
fileSize: _cli.config.upload.fileSizelimit
}
}));
app.use(_bodyParser2.default.json());
app.use(_bodyParser2.default.urlencoded({ extended: true }));

// depending on the way you serve this app, cookie.secure will be set
// in Production, this app has to be reverse-proxified
app.use((0, _expressSession2.default)({
name: 'sessionId',
secret: _cli.config.sessionSecret,
resave: false,
saveUninitialized: true,
cookie: { secure: _cli.config.cookie.secure },
proxy: true
}));
var pluginsPartials = _cli.Plugins.instance.getPartials();
Array.prototype.forEach.call(pluginsPartials, function (pluginPartials) {
app.use(_express2.default.static(pluginPartials));
});

_cli.Hooks.instance.trigger('afterExpress', app, _express2.default);

if (_cli.fileUtils.isFile(_cli.fileUtils.concatPath(_cli.config.root, 'cert.pem'))) {
var server = _https2.default.createServer(opts, app);
server.listen(port, function () {
console.log(_cliColor2.default.green('\nserver running at https://localhost:' + port + '/'));
if (process.env.OPENURL) _openurl2.default.open('https://localhost:' + port + '/abe/');
});
} else {
app.listen(port, function () {
console.log(_cliColor2.default.green('\nserver running at http://localhost:' + port + '/'));
if (process.env.OPENURL) _openurl2.default.open('http://localhost:' + port + '/abe/');
});
app.use(_express2.default.static(__dirname + '/node_modules/handlebars/dist'));
app.use((0, _connectBusboy2.default)({
limits: {
fileSize: _cli.config.upload.fileSizelimit
}
}));
app.use(_bodyParser2.default.json());
app.use(_bodyParser2.default.urlencoded({ extended: true }));

// depending on the way you serve this app, cookie.secure will be set
// in Production, this app has to be reverse-proxified
app.use((0, _expressSession2.default)({
name: 'sessionId',
secret: _cli.config.sessionSecret,
resave: false,
saveUninitialized: true,
cookie: { secure: _cli.config.cookie.secure },
proxy: true
}));

_cli.Hooks.instance.trigger('afterExpress', app, _express2.default);

if (_cli.fileUtils.isFile(_cli.fileUtils.concatPath(_cli.config.root, 'cert.pem'))) {
var server = _https2.default.createServer(opts, app);
server.listen(port, function () {
console.log(_cliColor2.default.green('\nserver running at https://localhost:' + port + '/'));
if (process.env.OPENURL) _openurl2.default.open('https://localhost:' + port + '/abe/');
});
} else {
app.listen(port, function () {
console.log(_cliColor2.default.green('\nserver running at http://localhost:' + port + '/'));
if (process.env.OPENURL) _openurl2.default.open('http://localhost:' + port + '/abe/');
});
}

// important : require here so config.root is defined
var controllers = require('./controllers');
app.use(controllers.default);
});
// important : require here so config.root is defined
var controllers = require('./controllers');
app.use(controllers.default);
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"on": "^1.3.0",
"openurl": "^1.1.0",
"pm2": "^1.1.3",
"portfinder": "^1.0.3",
"prettyjson": "^1.1.3",
"prompt": "^1.0.0",
"qs": "^6.0.1",
Expand Down
Loading

0 comments on commit 722c706

Please sign in to comment.