2017-11-27 17:09:51 +00:00
|
|
|
express = require("express")
|
|
|
|
app = express()
|
|
|
|
|
|
|
|
module.exports = MockProjectHistoryApi =
|
|
|
|
docs: {}
|
|
|
|
|
2018-03-08 17:24:54 +00:00
|
|
|
oldFiles: {}
|
|
|
|
|
|
|
|
addOldFile: (project_id, version, pathname, content) ->
|
|
|
|
@oldFiles["#{project_id}:#{version}:#{pathname}"] = content
|
|
|
|
|
2017-11-27 17:09:51 +00:00
|
|
|
run: () ->
|
|
|
|
app.post "/project", (req, res, next) =>
|
|
|
|
res.json project: id: 1
|
|
|
|
|
2018-03-08 17:24:54 +00:00
|
|
|
app.get "/project/:project_id/version/:version/:pathname", (req, res, next) =>
|
|
|
|
{project_id, version, pathname} = req.params
|
|
|
|
key = "#{project_id}:#{version}:#{pathname}"
|
|
|
|
if @oldFiles[key]?
|
|
|
|
res.send @oldFiles[key]
|
|
|
|
else
|
|
|
|
res.send 404
|
|
|
|
|
2017-11-27 17:09:51 +00:00
|
|
|
app.listen 3054, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
.on "error", (error) ->
|
|
|
|
console.error "error starting MockProjectHistoryApi:", error.message
|
|
|
|
process.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
MockProjectHistoryApi.run()
|