more moving of nginx code

This commit is contained in:
Girish Ramakrishnan
2015-12-11 14:48:02 -08:00
parent a7480c3f29
commit 39c626dc75
2 changed files with 46 additions and 38 deletions

View File

@@ -3,6 +3,7 @@
'use strict';
var config = require('./config.js'),
debug = require('debug')('src/nginx.js'),
ejs = require('ejs'),
fs = require('fs'),
path = require('path'),
@@ -12,6 +13,8 @@ var config = require('./config.js'),
exports = module.exports = {
configureAdmin: configureAdmin,
configureApp: configureApp,
unconfigureApp: unconfigureApp,
reload: reload
};
@@ -35,6 +38,43 @@ function configureAdmin(certFilePath, keyFilePath, callback) {
reload(callback);
}
function configureApp(app, certFilePath, keyFilePath, callback) {
var sourceDir = path.resolve(__dirname, '..');
var endpoint = app.oauthProxy ? 'oauthproxy' : 'app';
var vhost = config.appFqdn(app.location);
var data = {
sourceDir: sourceDir,
adminOrigin: config.adminOrigin(),
vhost: vhost,
port: app.httpPort,
endpoint: endpoint,
certFilePath: certFilePath,
keyFilePath: keyFilePath
};
var nginxConf = ejs.render(NGINX_APPCONFIG_EJS, data);
var nginxConfigFilename = path.join(paths.NGINX_APPCONFIG_DIR, app.id + '.conf');
debug('writing config for "%s" to %s', app.location, nginxConfigFilename);
if (!safe.fs.writeFileSync(nginxConfigFilename, nginxConf)) {
debug('Error creating nginx config for "%s" : %s', app.location, safe.error.message);
return callback(safe.error);
}
reload(callback);
}
function unconfigureApp(app, callback) {
var nginxConfigFilename = path.join(paths.NGINX_APPCONFIG_DIR, app.id + '.conf');
if (!safe.fs.unlinkSync(nginxConfigFilename)) {
debug('Error removing nginx configuration of "%s": %s', app.location, safe.error.message);
return callback(null);
}
reload(callback);
}
function reload(callback) {
shell.sudo('reload', [ RELOAD_NGINX_CMD ], callback);
}