2016-04-20 10:03:55 +00:00
|
|
|
// external modules
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
// configs
|
|
|
|
var env = process.env.NODE_ENV || 'development';
|
|
|
|
var config = require(path.join(__dirname, '..', 'config.json'))[env];
|
|
|
|
var debug = process.env.DEBUG ? (process.env.DEBUG === 'true') : ((typeof config.debug === 'boolean') ? config.debug : (env === 'development'));
|
|
|
|
|
|
|
|
// url
|
2016-10-10 13:16:58 +00:00
|
|
|
var domain = process.env.DOMAIN || process.env.HMD_DOMAIN || config.domain || '';
|
|
|
|
var urlpath = process.env.URL_PATH || process.env.HMD_URL_PATH || config.urlpath || '';
|
|
|
|
var port = process.env.PORT || process.env.HMD_PORT || config.port || 3000;
|
|
|
|
var alloworigin = process.env.HMD_ALLOW_ORIGIN ? process.env.HMD_ALLOW_ORIGIN.split(',') : (config.alloworigin || ['localhost']);
|
2016-04-20 10:03:55 +00:00
|
|
|
|
|
|
|
var usessl = !!config.usessl;
|
2016-10-10 13:16:58 +00:00
|
|
|
var protocolusessl = (usessl === true && typeof process.env.HMD_PROTOCOL_USESSL === 'undefined' && typeof config.protocolusessl === 'undefined')
|
|
|
|
? true : (process.env.HMD_PROTOCOL_USESSL ? (process.env.HMD_PROTOCOL_USESSL === 'true') : !!config.protocolusessl);
|
|
|
|
var urladdport = process.env.HMD_URL_ADDPORT ? (process.env.HMD_URL_ADDPORT === 'true') : !!config.urladdport;
|
2016-04-20 10:03:55 +00:00
|
|
|
|
2016-10-23 14:42:47 +00:00
|
|
|
var usecdn = process.env.HMD_USECDN ? (process.env.HMD_USECDN === 'true') : ((typeof config.usecdn === 'boolean') ? config.usecdn : true);
|
2016-04-20 10:03:55 +00:00
|
|
|
|
|
|
|
// db
|
|
|
|
var db = config.db || {
|
|
|
|
dialect: 'sqlite',
|
|
|
|
storage: './db.hackmd.sqlite'
|
|
|
|
};
|
|
|
|
|
|
|
|
// ssl path
|
2016-04-23 10:58:24 +00:00
|
|
|
var sslkeypath = config.sslkeypath || '';
|
2016-04-20 10:03:55 +00:00
|
|
|
var sslcertpath = config.sslcertpath || '';
|
|
|
|
var sslcapath = config.sslcapath || '';
|
|
|
|
var dhparampath = config.dhparampath || '';
|
|
|
|
|
|
|
|
// other path
|
|
|
|
var tmppath = config.tmppath || './tmp';
|
|
|
|
var defaultnotepath = config.defaultnotepath || './public/default.md';
|
|
|
|
var docspath = config.docspath || './public/docs';
|
|
|
|
var indexpath = config.indexpath || './public/views/index.ejs';
|
|
|
|
var hackmdpath = config.hackmdpath || './public/views/hackmd.ejs';
|
|
|
|
var errorpath = config.errorpath || './public/views/error.ejs';
|
|
|
|
var prettypath = config.prettypath || './public/views/pretty.ejs';
|
2016-05-29 09:54:24 +00:00
|
|
|
var slidepath = config.slidepath || './public/views/slide.ejs';
|
2016-04-20 10:03:55 +00:00
|
|
|
|
|
|
|
// session
|
|
|
|
var sessionname = config.sessionname || 'connect.sid';
|
|
|
|
var sessionsecret = config.sessionsecret || 'secret';
|
|
|
|
var sessionlife = config.sessionlife || 14 * 24 * 60 * 60 * 1000; //14 days
|
|
|
|
|
|
|
|
// static files
|
|
|
|
var staticcachetime = config.staticcachetime || 1 * 24 * 60 * 60 * 1000; // 1 day
|
|
|
|
|
|
|
|
// socket.io
|
2016-10-23 13:42:27 +00:00
|
|
|
var heartbeatinterval = config.heartbeatinterval || 5000;
|
|
|
|
var heartbeattimeout = config.heartbeattimeout || 10000;
|
2016-04-20 10:03:55 +00:00
|
|
|
|
|
|
|
// document
|
|
|
|
var documentmaxlength = config.documentmaxlength || 100000;
|
|
|
|
|
2016-11-14 09:07:07 +00:00
|
|
|
// image upload setting, available options are imgur/s3/filesystem
|
2016-11-17 08:28:02 +00:00
|
|
|
var imageUploadType = process.env.HMD_IMAGE_UPLOAD_TYPE || config.imageUploadType || 'imgur';
|
2016-11-14 09:07:07 +00:00
|
|
|
|
2016-11-16 04:05:24 +00:00
|
|
|
config.s3 = config.s3 || {};
|
2016-11-16 06:44:35 +00:00
|
|
|
var s3 = {
|
2016-11-17 08:28:02 +00:00
|
|
|
accessKeyId: process.env.HMD_S3_ACCESS_KEY_ID || config.s3.accessKeyId,
|
|
|
|
secretAccessKey: process.env.HMD_S3_SECRET_ACCESS_KEY || config.s3.secretAccessKey,
|
|
|
|
region: process.env.HMD_S3_REGION || config.s3.region
|
2016-11-16 06:44:35 +00:00
|
|
|
}
|
2016-11-17 08:28:02 +00:00
|
|
|
var s3bucket = process.env.HMD_S3_BUCKET || config.s3.bucket;
|
2016-11-16 04:05:24 +00:00
|
|
|
|
2016-04-20 10:03:55 +00:00
|
|
|
// auth
|
2016-10-10 13:16:58 +00:00
|
|
|
var facebook = (process.env.HMD_FACEBOOK_CLIENTID && process.env.HMD_FACEBOOK_CLIENTSECRET) ? {
|
|
|
|
clientID: process.env.HMD_FACEBOOK_CLIENTID,
|
|
|
|
clientSecret: process.env.HMD_FACEBOOK_CLIENTSECRET
|
|
|
|
} : config.facebook || false;
|
|
|
|
var twitter = (process.env.HMD_TWITTER_CONSUMERKEY && process.env.HMD_TWITTER_CONSUMERSECRET) ? {
|
|
|
|
consumerKey: process.env.HMD_TWITTER_CONSUMERKEY,
|
|
|
|
consumerSecret: process.env.HMD_TWITTER_CONSUMERSECRET
|
|
|
|
} : config.twitter || false;
|
|
|
|
var github = (process.env.HMD_GITHUB_CLIENTID && process.env.HMD_GITHUB_CLIENTSECRET) ? {
|
|
|
|
clientID: process.env.HMD_GITHUB_CLIENTID,
|
|
|
|
clientSecret: process.env.HMD_GITHUB_CLIENTSECRET
|
|
|
|
} : config.github || false;
|
|
|
|
var gitlab = (process.env.HMD_GITLAB_CLIENTID && process.env.HMD_GITLAB_CLIENTSECRET) ? {
|
|
|
|
baseURL: process.env.HMD_GITLAB_BASEURL,
|
|
|
|
clientID: process.env.HMD_GITLAB_CLIENTID,
|
|
|
|
clientSecret: process.env.HMD_GITLAB_CLIENTSECRET
|
|
|
|
} : config.gitlab || false;
|
|
|
|
var dropbox = (process.env.HMD_DROPBOX_CLIENTID && process.env.HMD_DROPBOX_CLIENTSECRET) ? {
|
|
|
|
clientID: process.env.HMD_DROPBOX_CLIENTID,
|
|
|
|
clientSecret: process.env.HMD_DROPBOX_CLIENTSECRET
|
|
|
|
} : config.dropbox || false;
|
|
|
|
var google = (process.env.HMD_GOOGLE_CLIENTID && process.env.HMD_GOOGLE_CLIENTSECRET) ? {
|
|
|
|
clientID: process.env.HMD_GOOGLE_CLIENTID,
|
|
|
|
clientSecret: process.env.HMD_GOOGLE_CLIENTSECRET
|
|
|
|
} : config.google || false;
|
|
|
|
var imgur = process.env.HMD_IMGUR_CLIENTID || config.imgur || false;
|
2016-04-20 10:03:55 +00:00
|
|
|
|
|
|
|
function getserverurl() {
|
2016-04-21 19:33:24 +00:00
|
|
|
var url = '';
|
|
|
|
if (domain) {
|
|
|
|
var protocol = protocolusessl ? 'https://' : 'http://';
|
|
|
|
url = protocol + domain;
|
|
|
|
if (urladdport && ((usessl && port != 443) || (!usessl && port != 80)))
|
|
|
|
url += ':' + port;
|
|
|
|
}
|
2016-04-20 10:03:55 +00:00
|
|
|
if (urlpath)
|
|
|
|
url += '/' + urlpath;
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2016-10-11 03:01:05 +00:00
|
|
|
var version = '0.4.5';
|
|
|
|
var minimumCompatibleVersion = '0.4.5';
|
2016-06-17 08:09:33 +00:00
|
|
|
var maintenance = true;
|
2016-04-20 10:03:55 +00:00
|
|
|
var cwd = path.join(__dirname, '..');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
version: version,
|
2016-06-17 08:31:36 +00:00
|
|
|
minimumCompatibleVersion: minimumCompatibleVersion,
|
2016-06-01 06:18:54 +00:00
|
|
|
maintenance: maintenance,
|
2016-04-20 10:03:55 +00:00
|
|
|
debug: debug,
|
|
|
|
urlpath: urlpath,
|
|
|
|
port: port,
|
|
|
|
alloworigin: alloworigin,
|
|
|
|
usessl: usessl,
|
|
|
|
serverurl: getserverurl(),
|
|
|
|
usecdn: usecdn,
|
|
|
|
db: db,
|
|
|
|
sslkeypath: path.join(cwd, sslkeypath),
|
|
|
|
sslcertpath: path.join(cwd, sslcertpath),
|
|
|
|
sslcapath: path.join(cwd, sslcapath),
|
|
|
|
dhparampath: path.join(cwd, dhparampath),
|
|
|
|
tmppath: path.join(cwd, tmppath),
|
|
|
|
defaultnotepath: path.join(cwd, defaultnotepath),
|
|
|
|
docspath: path.join(cwd, docspath),
|
|
|
|
indexpath: path.join(cwd, indexpath),
|
|
|
|
hackmdpath: path.join(cwd, hackmdpath),
|
|
|
|
errorpath: path.join(cwd, errorpath),
|
|
|
|
prettypath: path.join(cwd, prettypath),
|
|
|
|
slidepath: path.join(cwd, slidepath),
|
|
|
|
sessionname: sessionname,
|
|
|
|
sessionsecret: sessionsecret,
|
|
|
|
sessionlife: sessionlife,
|
|
|
|
staticcachetime: staticcachetime,
|
|
|
|
heartbeatinterval: heartbeatinterval,
|
|
|
|
heartbeattimeout: heartbeattimeout,
|
|
|
|
documentmaxlength: documentmaxlength,
|
|
|
|
facebook: facebook,
|
|
|
|
twitter: twitter,
|
|
|
|
github: github,
|
2016-05-09 22:31:49 +00:00
|
|
|
gitlab: gitlab,
|
2016-04-20 10:03:55 +00:00
|
|
|
dropbox: dropbox,
|
2016-05-21 14:48:00 +00:00
|
|
|
google: google,
|
2016-11-14 09:07:07 +00:00
|
|
|
imgur: imgur,
|
2016-11-16 04:05:24 +00:00
|
|
|
imageUploadType: imageUploadType,
|
|
|
|
s3: s3,
|
|
|
|
s3bucket: s3bucket
|
2016-04-23 10:58:24 +00:00
|
|
|
};
|