|
@@ -128,26 +128,6 @@ const ForbidSymlinks = require('./app/js/StaticServerForbidSymlinks')
|
|
|
// create a static server which does not allow access to any symlinks
|
|
// create a static server which does not allow access to any symlinks
|
|
|
// avoids possible mismatch of root directory between middleware check
|
|
// avoids possible mismatch of root directory between middleware check
|
|
|
// and serving the files
|
|
// and serving the files
|
|
|
-const staticCompileServer = ForbidSymlinks(
|
|
|
|
|
- express.static,
|
|
|
|
|
- Settings.path.compilesDir,
|
|
|
|
|
- {
|
|
|
|
|
- setHeaders(res, path, stat) {
|
|
|
|
|
- if (Path.basename(path) === 'output.pdf') {
|
|
|
|
|
- // Calculate an etag in the same way as nginx
|
|
|
|
|
- // https://github.com/tj/send/issues/65
|
|
|
|
|
- const etag = (path, stat) =>
|
|
|
|
|
- `"${Math.ceil(+stat.mtime / 1000).toString(16)}` +
|
|
|
|
|
- '-' +
|
|
|
|
|
- Number(stat.size).toString(16) +
|
|
|
|
|
- '"'
|
|
|
|
|
- res.set('Etag', etag(path, stat))
|
|
|
|
|
- }
|
|
|
|
|
- res.set('Content-Type', ContentTypeMapper.map(path))
|
|
|
|
|
- },
|
|
|
|
|
- }
|
|
|
|
|
-)
|
|
|
|
|
-
|
|
|
|
|
const staticOutputServer = ForbidSymlinks(
|
|
const staticOutputServer = ForbidSymlinks(
|
|
|
express.static,
|
|
express.static,
|
|
|
Settings.path.outputDir,
|
|
Settings.path.outputDir,
|
|
@@ -213,32 +193,6 @@ app.get(
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-app.get(
|
|
|
|
|
- '/project/:project_id/user/:user_id/output/*',
|
|
|
|
|
- function (req, res, next) {
|
|
|
|
|
- // for specific user get the path to the top level file
|
|
|
|
|
- logger.warn(
|
|
|
|
|
- { url: req.url },
|
|
|
|
|
- 'direct request for file in compile directory'
|
|
|
|
|
- )
|
|
|
|
|
- req.url = `/${req.params.project_id}-${req.params.user_id}/${req.params[0]}`
|
|
|
|
|
- staticCompileServer(req, res, next)
|
|
|
|
|
- }
|
|
|
|
|
-)
|
|
|
|
|
-
|
|
|
|
|
-app.get('/project/:project_id/output/*', function (req, res, next) {
|
|
|
|
|
- logger.warn({ url: req.url }, 'direct request for file in compile directory')
|
|
|
|
|
- if (req.query?.build?.match(OutputCacheManager.BUILD_REGEX)) {
|
|
|
|
|
- // for specific build get the path from the OutputCacheManager (e.g. .clsi/buildId)
|
|
|
|
|
- req.url =
|
|
|
|
|
- `/${req.params.project_id}/` +
|
|
|
|
|
- OutputCacheManager.path(req.query.build, `/${req.params[0]}`)
|
|
|
|
|
- } else {
|
|
|
|
|
- req.url = `/${req.params.project_id}/${req.params[0]}`
|
|
|
|
|
- }
|
|
|
|
|
- staticCompileServer(req, res, next)
|
|
|
|
|
-})
|
|
|
|
|
-
|
|
|
|
|
app.get('/oops', function (req, res, next) {
|
|
app.get('/oops', function (req, res, next) {
|
|
|
logger.error({ err: 'hello' }, 'test error')
|
|
logger.error({ err: 'hello' }, 'test error')
|
|
|
res.send('error\n')
|
|
res.send('error\n')
|