From 0ed4b50098b4329b1d91e519bbbbe4e14701f92f Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Sun, 24 Jun 2018 00:06:03 +0200 Subject: Move config out of statics path Since static path is providing with a high expiration data, we provide configs via API. This shouldn't add any noticeable load while making it uncached and this way working again. Signed-off-by: Sheogorath --- app.js | 16 ---------------- lib/config/default.js | 1 + lib/config/index.js | 1 + lib/web/statusRouter.js | 17 +++++++++++++++++ public/views/includes/scripts.ejs | 2 +- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app.js b/app.js index fcb5305c..bfb5a49a 100644 --- a/app.js +++ b/app.js @@ -26,22 +26,6 @@ var response = require('./lib/response') var models = require('./lib/models') 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 var app = express() var server = null diff --git a/lib/config/default.js b/lib/config/default.js index f88c17b3..2a91c852 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -45,6 +45,7 @@ module.exports = { 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', diff --git a/lib/config/index.js b/lib/config/index.js index b8bf64cc..79330443 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -173,6 +173,7 @@ config.hackmdPath = path.join(appRootPath, config.hackmdPath) 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) // make config readonly diff --git a/lib/web/statusRouter.js b/lib/web/statusRouter.js index d22fac47..4495a28e 100644 --- a/lib/web/statusRouter.js +++ b/lib/web/statusRouter.js @@ -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) +}) diff --git a/public/views/includes/scripts.ejs b/public/views/includes/scripts.ejs index 8766894a..df8fbc00 100644 --- a/public/views/includes/scripts.ejs +++ b/public/views/includes/scripts.ejs @@ -1,4 +1,4 @@ - + <% for (var chunk in htmlWebpackPlugin.files.chunks) { %> <% } %> -- cgit v1.2.3