Explorar o código

rename staticServer to staticCompileServer

Brian Gough %!s(int64=5) %!d(string=hai) anos
pai
achega
bdbfe70086
Modificáronse 1 ficheiros con 21 adicións e 17 borrados
  1. 21 17
      services/clsi/app.js

+ 21 - 17
services/clsi/app.js

@@ -118,21 +118,25 @@ 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 staticServer = 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))
+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))
+      }
+      return res.set('Content-Type', ContentTypeMapper.map(path))
     }
     }
-    return res.set('Content-Type', ContentTypeMapper.map(path))
   }
   }
-})
+)
 
 
 app.get(
 app.get(
   '/project/:project_id/user/:user_id/build/:build_id/output/*',
   '/project/:project_id/user/:user_id/build/:build_id/output/*',
@@ -141,7 +145,7 @@ app.get(
     req.url =
     req.url =
       `/${req.params.project_id}-${req.params.user_id}/` +
       `/${req.params.project_id}-${req.params.user_id}/` +
       OutputCacheManager.path(req.params.build_id, `/${req.params[0]}`)
       OutputCacheManager.path(req.params.build_id, `/${req.params[0]}`)
-    return staticServer(req, res, next)
+    return staticCompileServer(req, res, next)
   }
   }
 )
 )
 
 
@@ -154,7 +158,7 @@ app.get('/project/:project_id/build/:build_id/output/*', function (
   req.url =
   req.url =
     `/${req.params.project_id}/` +
     `/${req.params.project_id}/` +
     OutputCacheManager.path(req.params.build_id, `/${req.params[0]}`)
     OutputCacheManager.path(req.params.build_id, `/${req.params[0]}`)
-  return staticServer(req, res, next)
+  return staticCompileServer(req, res, next)
 })
 })
 
 
 app.get('/project/:project_id/user/:user_id/output/*', function (
 app.get('/project/:project_id/user/:user_id/output/*', function (
@@ -164,7 +168,7 @@ app.get('/project/:project_id/user/:user_id/output/*', function (
 ) {
 ) {
   // for specific user get the path to the top level file
   // for specific user get the path to the top level file
   req.url = `/${req.params.project_id}-${req.params.user_id}/${req.params[0]}`
   req.url = `/${req.params.project_id}-${req.params.user_id}/${req.params[0]}`
-  return staticServer(req, res, next)
+  return staticCompileServer(req, res, next)
 })
 })
 
 
 app.get('/project/:project_id/output/*', function (req, res, next) {
 app.get('/project/:project_id/output/*', function (req, res, next) {
@@ -179,7 +183,7 @@ app.get('/project/:project_id/output/*', function (req, res, next) {
   } else {
   } else {
     req.url = `/${req.params.project_id}/${req.params[0]}`
     req.url = `/${req.params.project_id}/${req.params[0]}`
   }
   }
-  return staticServer(req, res, next)
+  return staticCompileServer(req, res, next)
 })
 })
 
 
 app.get('/oops', function (req, res, next) {
 app.get('/oops', function (req, res, next) {