2017-11-27 17:09:51 +00:00
|
|
|
express = require("express")
|
|
|
|
app = express()
|
|
|
|
|
|
|
|
module.exports = MockFileStoreApi =
|
|
|
|
files: {}
|
|
|
|
|
|
|
|
run: () ->
|
|
|
|
app.post "/project/:project_id/file/:file_id", (req, res, next) =>
|
2018-02-14 15:12:46 +00:00
|
|
|
chunks = []
|
|
|
|
req.on 'data', (chunk) ->
|
|
|
|
chunks.push(chunk)
|
2017-11-27 17:09:51 +00:00
|
|
|
|
2018-01-25 16:58:48 +00:00
|
|
|
req.on 'end', =>
|
2018-02-14 15:12:46 +00:00
|
|
|
content = Buffer.concat(chunks).toString()
|
2018-01-25 16:58:48 +00:00
|
|
|
{project_id, file_id} = req.params
|
|
|
|
@files[project_id] ?= {}
|
2018-02-14 15:12:46 +00:00
|
|
|
@files[project_id][file_id] = { content }
|
2018-01-25 16:58:48 +00:00
|
|
|
res.sendStatus 200
|
2017-11-27 17:09:51 +00:00
|
|
|
|
2018-02-14 15:12:46 +00:00
|
|
|
app.get "/project/:project_id/file/:file_id", (req, res, next) =>
|
|
|
|
{project_id, file_id} = req.params
|
|
|
|
{ content } = @files[project_id][file_id]
|
|
|
|
res.send content
|
|
|
|
|
2017-11-27 17:09:51 +00:00
|
|
|
app.listen 3009, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
.on "error", (error) ->
|
|
|
|
console.error "error starting MockFileStoreApi:", error.message
|
|
|
|
process.exit(1)
|
|
|
|
|
|
|
|
MockFileStoreApi.run()
|