mirror of
https://github.com/SunRed/haste-server.git
synced 2024-11-23 17:50:19 +01:00
Copying example config in case config doesn't exist & env vars
This change makes it possible to start haste server with no further configuration, supporting "out-of-box" solutions for Heroku / Dokku and preferrably other platforms
This commit is contained in:
parent
63d2568f91
commit
58c37bf677
1 changed files with 49 additions and 41 deletions
16
server.js
16
server.js
|
@ -10,10 +10,20 @@ const HasteUtils = require('./lib/util');
|
||||||
|
|
||||||
const utils = new HasteUtils();
|
const utils = new HasteUtils();
|
||||||
|
|
||||||
|
(async function(){
|
||||||
|
|
||||||
|
//"out-of-box" support - copy example config if it doesn't exist
|
||||||
|
if (!fs.existsSync('./config.js')){
|
||||||
|
await fs.promises.copyFile('./example.config.js', './config.js').catch(err => {
|
||||||
|
winston.error('failed to copy example config', {error: err});
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
//load config and set some defaults
|
//load config and set some defaults
|
||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
config.port = config.port || 7777;
|
|
||||||
config.host = config.host || '127.0.0.1';
|
config.host = process.env.HASTE_HOST || config.host || '127.0.0.1';
|
||||||
|
config.port = process.env.HASTE_PORT || config.port || 7777;
|
||||||
|
|
||||||
//set up logger
|
//set up logger
|
||||||
winston.add(new winston.transports.Console({
|
winston.add(new winston.transports.Console({
|
||||||
|
@ -51,8 +61,6 @@ if (config.compressStaticAssets){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(async function(){
|
|
||||||
|
|
||||||
//send the static documents into the preferred store, skipping expirations
|
//send the static documents into the preferred store, skipping expirations
|
||||||
for (const name in config.documents){
|
for (const name in config.documents){
|
||||||
let path = config.documents[name];
|
let path = config.documents[name];
|
||||||
|
|
Loading…
Reference in a new issue