Merge pull request #855 from hackmdio/fix/constants
Move config out of statics path
This commit is contained in:
commit
b8726bbe8d
5 changed files with 20 additions and 17 deletions
16
app.js
16
app.js
|
@ -26,22 +26,6 @@ var response = require('./lib/response')
|
||||||
var models = require('./lib/models')
|
var models = require('./lib/models')
|
||||||
var csp = require('./lib/csp')
|
var csp = require('./lib/csp')
|
||||||
|
|
||||||
// generate front-end constants by template
|
|
||||||
var constpath = path.join(__dirname, './public/js/lib/common/constant.ejs')
|
|
||||||
var data = {
|
|
||||||
domain: config.domain,
|
|
||||||
urlpath: config.urlPath,
|
|
||||||
debug: config.debug,
|
|
||||||
version: config.version,
|
|
||||||
DROPBOX_APP_KEY: config.dropbox.appKey,
|
|
||||||
allowedUploadMimeTypes: config.allowedUploadMimeTypes
|
|
||||||
}
|
|
||||||
|
|
||||||
ejs.renderFile(constpath, data, {}, function (err, str) {
|
|
||||||
if (err) throw new Error(err)
|
|
||||||
fs.writeFileSync(path.join(__dirname, './public/build/constant.js'), str)
|
|
||||||
})
|
|
||||||
|
|
||||||
// server setup
|
// server setup
|
||||||
var app = express()
|
var app = express()
|
||||||
var server = null
|
var server = null
|
||||||
|
|
|
@ -45,6 +45,7 @@ module.exports = {
|
||||||
errorPath: './public/views/error.ejs',
|
errorPath: './public/views/error.ejs',
|
||||||
prettyPath: './public/views/pretty.ejs',
|
prettyPath: './public/views/pretty.ejs',
|
||||||
slidePath: './public/views/slide.ejs',
|
slidePath: './public/views/slide.ejs',
|
||||||
|
constantsPath: './public/js/lib/common/constant.ejs',
|
||||||
uploadsPath: './public/uploads',
|
uploadsPath: './public/uploads',
|
||||||
// session
|
// session
|
||||||
sessionName: 'connect.sid',
|
sessionName: 'connect.sid',
|
||||||
|
|
|
@ -173,6 +173,7 @@ config.hackmdPath = path.join(appRootPath, config.hackmdPath)
|
||||||
config.errorPath = path.join(appRootPath, config.errorPath)
|
config.errorPath = path.join(appRootPath, config.errorPath)
|
||||||
config.prettyPath = path.join(appRootPath, config.prettyPath)
|
config.prettyPath = path.join(appRootPath, config.prettyPath)
|
||||||
config.slidePath = path.join(appRootPath, config.slidePath)
|
config.slidePath = path.join(appRootPath, config.slidePath)
|
||||||
|
config.constantsPath = path.join(appRootPath, config.constantsPath)
|
||||||
config.uploadsPath = path.join(appRootPath, config.uploadsPath)
|
config.uploadsPath = path.join(appRootPath, config.uploadsPath)
|
||||||
|
|
||||||
// make config readonly
|
// make config readonly
|
||||||
|
|
|
@ -90,3 +90,20 @@ statusRouter.post('/temp', urlencodedParser, function (req, res) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
statusRouter.get('/config', function (req, res) {
|
||||||
|
var data = {
|
||||||
|
domain: config.domain,
|
||||||
|
urlpath: config.urlPath,
|
||||||
|
debug: config.debug,
|
||||||
|
version: config.version,
|
||||||
|
DROPBOX_APP_KEY: config.dropbox.appKey,
|
||||||
|
allowedUploadMimeTypes: config.allowedUploadMimeTypes
|
||||||
|
}
|
||||||
|
res.set({
|
||||||
|
'Cache-Control': 'private', // only cache by client
|
||||||
|
'X-Robots-Tag': 'noindex, nofollow', // prevent crawling
|
||||||
|
'HackMD-Version': config.version
|
||||||
|
})
|
||||||
|
res.render(config.constantsPath, data)
|
||||||
|
})
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<script src="<%= webpackConfig.output.baseUrl %>/build/constant.js"></script>
|
<script src="<%= webpackConfig.output.baseUrl %>/config"></script>
|
||||||
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
|
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
|
||||||
<script src="<%= webpackConfig.output.baseUrl %><%= htmlWebpackPlugin.files.chunks[chunk].entry %>" defer></script>
|
<script src="<%= webpackConfig.output.baseUrl %><%= htmlWebpackPlugin.files.chunks[chunk].entry %>" defer></script>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
Loading…
Reference in a new issue