2019-01-27 14:54:29 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const ejs = require('ejs');
|
|
|
|
const fs = require('fs');
|
|
|
|
const program = require('commander');
|
|
|
|
|
2019-03-02 16:15:28 +00:00
|
|
|
let backend;
|
|
|
|
|
2019-01-27 14:54:29 +00:00
|
|
|
program
|
|
|
|
.version('0.1.0')
|
|
|
|
.option('-p, --production', 'Render template for production.')
|
2019-03-02 16:15:28 +00:00
|
|
|
.arguments('[backend]')
|
|
|
|
.action((backendArg) => backend = backendArg)
|
2019-01-27 14:54:29 +00:00
|
|
|
.parse(process.argv)
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
production: false,
|
|
|
|
}
|
|
|
|
|
2019-03-02 16:15:28 +00:00
|
|
|
if (!backend) {
|
|
|
|
backend = 'http://192.168.240.1:9091'
|
|
|
|
}
|
|
|
|
|
2019-01-27 14:54:29 +00:00
|
|
|
if (program.production) {
|
|
|
|
options['production'] = true;
|
|
|
|
}
|
|
|
|
|
2019-03-02 16:15:28 +00:00
|
|
|
options['authelia_backend'] = backend;
|
|
|
|
|
2019-01-30 15:47:03 +00:00
|
|
|
const templatePath = __dirname + '/nginx.conf.ejs';
|
|
|
|
const outputPath = __dirname + '/nginx.conf';
|
|
|
|
|
|
|
|
html = ejs.renderFile(templatePath, options, (err, conf) => {
|
|
|
|
try {
|
|
|
|
var fd = fs.openSync(outputPath, 'w');
|
|
|
|
fs.writeFileSync(fd, conf);
|
|
|
|
} catch (e) {
|
|
|
|
fs.writeFileSync(outputPath, conf);
|
|
|
|
}
|
2019-01-27 14:54:29 +00:00
|
|
|
});
|