allow direct path to output file /project/project_id/build/build_id/output/*

this avoids use of the query string ?build=... and so we can match the
url directly with the nginx location directive
This commit is contained in:
Brian Gough 2016-05-13 10:10:48 +01:00
parent d5c1fb9997
commit 8a2665911d

View file

@ -42,6 +42,13 @@ app.param 'project_id', (req, res, next, project_id) ->
else else
next new Error("invalid project id") next new Error("invalid project id")
app.param 'build_id', (req, res, next, build_id) ->
if build_id?.match OutputCacheManager.BUILD_REGEX
next()
else
next new Error("invalid build id #{build_id}")
app.post "/project/:project_id/compile", bodyParser.json(limit: "5mb"), CompileController.compile app.post "/project/:project_id/compile", bodyParser.json(limit: "5mb"), CompileController.compile
app.delete "/project/:project_id", CompileController.clearCache app.delete "/project/:project_id", CompileController.clearCache
@ -65,6 +72,11 @@ staticServer = ForbidSymlinks express.static, Settings.path.compilesDir, setHead
res.set("Etag", etag(path, stat)) res.set("Etag", etag(path, stat))
res.set("Content-Type", ContentTypeMapper.map(path)) res.set("Content-Type", ContentTypeMapper.map(path))
app.get "/project/:project_id/build/:build_id/output/*", (req, res, next) ->
# for specific build get the path from the OutputCacheManager (e.g. .clsi/buildId)
req.url = "/#{req.params.project_id}/" + OutputCacheManager.path(req.params.build_id, "/#{req.params[0]}")
staticServer(req, res, next)
app.get "/project/:project_id/output/*", (req, res, next) -> app.get "/project/:project_id/output/*", (req, res, next) ->
if req.query?.build? && req.query.build.match(OutputCacheManager.BUILD_REGEX) if req.query?.build? && req.query.build.match(OutputCacheManager.BUILD_REGEX)
# for specific build get the path from the OutputCacheManager (e.g. .clsi/buildId) # for specific build get the path from the OutputCacheManager (e.g. .clsi/buildId)