Skip to content

Commit b8726bb

Browse files
authored
Merge pull request #855 from hackmdio/fix/constants
Move config out of statics path
2 parents cfdfafd + 0ed4b50 commit b8726bb

5 files changed

Lines changed: 20 additions & 17 deletions

File tree

app.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,6 @@ var response = require('./lib/response')
2626
var models = require('./lib/models')
2727
var csp = require('./lib/csp')
2828

29-
// generate front-end constants by template
30-
var constpath = path.join(__dirname, './public/js/lib/common/constant.ejs')
31-
var data = {
32-
domain: config.domain,
33-
urlpath: config.urlPath,
34-
debug: config.debug,
35-
version: config.version,
36-
DROPBOX_APP_KEY: config.dropbox.appKey,
37-
allowedUploadMimeTypes: config.allowedUploadMimeTypes
38-
}
39-
40-
ejs.renderFile(constpath, data, {}, function (err, str) {
41-
if (err) throw new Error(err)
42-
fs.writeFileSync(path.join(__dirname, './public/build/constant.js'), str)
43-
})
44-
4529
// server setup
4630
var app = express()
4731
var server = null

lib/config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ module.exports = {
4545
errorPath: './public/views/error.ejs',
4646
prettyPath: './public/views/pretty.ejs',
4747
slidePath: './public/views/slide.ejs',
48+
constantsPath: './public/js/lib/common/constant.ejs',
4849
uploadsPath: './public/uploads',
4950
// session
5051
sessionName: 'connect.sid',

lib/config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ config.hackmdPath = path.join(appRootPath, config.hackmdPath)
173173
config.errorPath = path.join(appRootPath, config.errorPath)
174174
config.prettyPath = path.join(appRootPath, config.prettyPath)
175175
config.slidePath = path.join(appRootPath, config.slidePath)
176+
config.constantsPath = path.join(appRootPath, config.constantsPath)
176177
config.uploadsPath = path.join(appRootPath, config.uploadsPath)
177178

178179
// make config readonly

lib/web/statusRouter.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,20 @@ statusRouter.post('/temp', urlencodedParser, function (req, res) {
9090
}
9191
}
9292
})
93+
94+
statusRouter.get('/config', function (req, res) {
95+
var data = {
96+
domain: config.domain,
97+
urlpath: config.urlPath,
98+
debug: config.debug,
99+
version: config.version,
100+
DROPBOX_APP_KEY: config.dropbox.appKey,
101+
allowedUploadMimeTypes: config.allowedUploadMimeTypes
102+
}
103+
res.set({
104+
'Cache-Control': 'private', // only cache by client
105+
'X-Robots-Tag': 'noindex, nofollow', // prevent crawling
106+
'HackMD-Version': config.version
107+
})
108+
res.render(config.constantsPath, data)
109+
})

public/views/includes/scripts.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script src="<%= webpackConfig.output.baseUrl %>/build/constant.js"></script>
1+
<script src="<%= webpackConfig.output.baseUrl %>/config"></script>
22
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
33
<script src="<%= webpackConfig.output.baseUrl %><%= htmlWebpackPlugin.files.chunks[chunk].entry %>" defer></script>
44
<% } %>

0 commit comments

Comments
 (0)