mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 02:05:21 -04:00
Merge pull request #940 from WilliButz/fix-configurable-paths
enhance configurabiltiy of paths & make execution path-independent
This commit is contained in:
commit
32af96aa37
8 changed files with 39 additions and 45 deletions
|
@ -38,15 +38,10 @@ module.exports = {
|
|||
sslCAPath: '',
|
||||
dhParamPath: '',
|
||||
// other path
|
||||
viewPath: './public/views',
|
||||
tmpPath: './tmp',
|
||||
defaultNotePath: './public/default.md',
|
||||
docsPath: './public/docs',
|
||||
indexPath: './public/views/index.ejs',
|
||||
codimdPath: './public/views/codimd.ejs',
|
||||
errorPath: './public/views/error.ejs',
|
||||
prettyPath: './public/views/pretty.ejs',
|
||||
slidePath: './public/views/slide.ejs',
|
||||
constantsPath: './public/js/lib/common/constant.ejs',
|
||||
uploadsPath: './public/uploads',
|
||||
// session
|
||||
sessionName: 'connect.sid',
|
||||
|
|
|
@ -9,7 +9,7 @@ const deepFreeze = require('deep-freeze')
|
|||
const {Environment, Permission} = require('./enum')
|
||||
const logger = require('../logger')
|
||||
|
||||
const appRootPath = path.join(__dirname, '../../')
|
||||
const appRootPath = path.resolve(__dirname, '../../')
|
||||
const env = process.env.NODE_ENV || Environment.development
|
||||
const debugConfig = {
|
||||
debug: (env === Environment.development)
|
||||
|
@ -23,7 +23,8 @@ const packageConfig = {
|
|||
minimumCompatibleVersion: '0.5.0'
|
||||
}
|
||||
|
||||
const configFilePath = path.join(appRootPath, 'config.json')
|
||||
const configFilePath = path.resolve(appRootPath, process.env.CMD_CONFIG_FILE ||
|
||||
'config.json')
|
||||
const fileConfig = fs.existsSync(configFilePath) ? require(configFilePath)[env] : undefined
|
||||
|
||||
let config = require('./default')
|
||||
|
@ -173,20 +174,14 @@ config.sslCAPath.forEach(function (capath, i, array) {
|
|||
array[i] = path.resolve(appRootPath, capath)
|
||||
})
|
||||
|
||||
config.sslCertPath = path.join(appRootPath, config.sslCertPath)
|
||||
config.sslKeyPath = path.join(appRootPath, config.sslKeyPath)
|
||||
config.dhParamPath = path.join(appRootPath, config.dhParamPath)
|
||||
|
||||
config.tmpPath = path.join(appRootPath, config.tmpPath)
|
||||
config.defaultNotePath = path.join(appRootPath, config.defaultNotePath)
|
||||
config.docsPath = path.join(appRootPath, config.docsPath)
|
||||
config.indexPath = path.join(appRootPath, config.indexPath)
|
||||
config.codimdPath = path.join(appRootPath, config.codimdPath)
|
||||
config.errorPath = path.join(appRootPath, config.errorPath)
|
||||
config.prettyPath = path.join(appRootPath, config.prettyPath)
|
||||
config.slidePath = path.join(appRootPath, config.slidePath)
|
||||
config.constantsPath = path.join(appRootPath, config.constantsPath)
|
||||
config.uploadsPath = path.join(appRootPath, config.uploadsPath)
|
||||
config.sslCertPath = path.resolve(appRootPath, config.sslCertPath)
|
||||
config.sslKeyPath = path.resolve(appRootPath, config.sslKeyPath)
|
||||
config.dhParamPath = path.resolve(appRootPath, config.dhParamPath)
|
||||
config.viewPath = path.resolve(appRootPath, config.viewPath)
|
||||
config.tmpPath = path.resolve(appRootPath, config.tmpPath)
|
||||
config.defaultNotePath = path.resolve(appRootPath, config.defaultNotePath)
|
||||
config.docsPath = path.resolve(appRootPath, config.docsPath)
|
||||
config.uploadsPath = path.resolve(appRootPath, config.uploadsPath)
|
||||
|
||||
// make config readonly
|
||||
config = deepFreeze(config)
|
||||
|
|
|
@ -5,6 +5,7 @@ var async = require('async')
|
|||
var moment = require('moment')
|
||||
var childProcess = require('child_process')
|
||||
var shortId = require('shortid')
|
||||
var path = require('path')
|
||||
|
||||
// core
|
||||
var config = require('../config')
|
||||
|
@ -14,7 +15,7 @@ var dmpWorker = createDmpWorker()
|
|||
var dmpCallbackCache = {}
|
||||
|
||||
function createDmpWorker () {
|
||||
var worker = childProcess.fork('./lib/workers/dmpWorker.js', {
|
||||
var worker = childProcess.fork(path.resolve(__dirname, '../workers/dmpWorker.js'), {
|
||||
stdio: 'ignore'
|
||||
})
|
||||
if (config.debug) logger.info('dmp worker process started')
|
||||
|
|
|
@ -54,7 +54,7 @@ var response = {
|
|||
}
|
||||
|
||||
function responseError (res, code, detail, msg) {
|
||||
res.status(code).render(config.errorPath, {
|
||||
res.status(code).render('error.ejs', {
|
||||
url: config.serverURL,
|
||||
title: code + ' ' + detail + ' ' + msg,
|
||||
code: code,
|
||||
|
@ -104,11 +104,11 @@ function showIndex (req, res, next) {
|
|||
}).then(function (user) {
|
||||
if (user) {
|
||||
data.deleteToken = user.deleteToken
|
||||
res.render(config.indexPath, data)
|
||||
res.render('index.ejs', data)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
res.render(config.indexPath, data)
|
||||
res.render('index.ejs', data)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ function responseCodiMD (res, note) {
|
|||
'Cache-Control': 'private', // only cache by client
|
||||
'X-Robots-Tag': 'noindex, nofollow' // prevent crawling
|
||||
})
|
||||
res.render(config.codimdPath, {
|
||||
res.render('codimd.ejs', {
|
||||
url: config.serverURL,
|
||||
title: title,
|
||||
useCDN: config.useCDN,
|
||||
|
@ -283,7 +283,7 @@ function renderPublish (data, res) {
|
|||
res.set({
|
||||
'Cache-Control': 'private' // only cache by client
|
||||
})
|
||||
res.render(config.prettyPath, data)
|
||||
res.render('pretty.ejs', data)
|
||||
}
|
||||
|
||||
function actionPublish (req, res, note) {
|
||||
|
@ -665,7 +665,7 @@ function renderPublishSlide (data, res) {
|
|||
res.set({
|
||||
'Cache-Control': 'private' // only cache by client
|
||||
})
|
||||
res.render(config.slidePath, data)
|
||||
res.render('slide.ejs', data)
|
||||
}
|
||||
|
||||
module.exports = response
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
'use strict'
|
||||
const url = require('url')
|
||||
const path = require('path')
|
||||
|
||||
const config = require('../../config')
|
||||
const logger = require('../../logger')
|
||||
|
@ -15,5 +16,5 @@ exports.uploadImage = function (imagePath, callback) {
|
|||
return
|
||||
}
|
||||
|
||||
callback(null, url.resolve(config.serverURL + '/', imagePath.match(/public\/(.+)$/)[1]))
|
||||
callback(null, url.resolve(config.serverURL + '/uploads/', path.basename(imagePath)))
|
||||
}
|
||||
|
|
|
@ -105,5 +105,5 @@ statusRouter.get('/config', function (req, res) {
|
|||
'X-Robots-Tag': 'noindex, nofollow', // prevent crawling
|
||||
'Content-Type': 'application/javascript'
|
||||
})
|
||||
res.render(config.constantsPath, data)
|
||||
res.render('../js/lib/common/constant.ejs', data)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue