Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "fscs", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "File System CRUD Server", | ||
@@ -5,0 +5,0 @@ "main": "./src/server.js", |
@@ -1,2 +0,2 @@ | ||
# fscs · [](https://github.com/elisherer/fscs/blob/master/LICENSE) [](https://www.npmjs.com/package/fscs)   | ||
# fscs · [](https://github.com/elisherer/fscs/blob/master/LICENSE) [](https://www.npmjs.com/package/fscs)   | ||
@@ -121,2 +121,2 @@ File System CRUD server | ||
fscs is [MIT Licensed](https://github.com/elisherer/fscs/blob/master/LICENSE) | ||
fscs is [MIT Licensed](https://github.com/elisherer/fscs/blob/master/LICENSE) |
module.exports = ctx => { | ||
const { res } = ctx; | ||
const { req, res } = ctx; | ||
res.setHeader("Access-Control-Allow-Origin", "*"); | ||
res.setHeader("Access-Control-Allow-Headers", "Authorization,Content-Type"); | ||
res.setHeader("Access-Control-Allow-Headers", "Authorization,Content-Type,If-Modified-Since"); | ||
res.setHeader("Access-Control-Allow-Methods", "GET,POST,PATCH,PUT,DELETE,OPTIONS"); | ||
if (req.method === 'OPTIONS') { | ||
res.statusCode = 200; | ||
res.end(); | ||
return true; | ||
} | ||
}; |
@@ -140,10 +140,15 @@ const fs = require("fs"); | ||
const stream = fs.createWriteStream(filePath); | ||
req.pipe(stream); // TODO: limit data length? | ||
stream.on("end", function () { | ||
res.statusCode = 204; | ||
res.end(); | ||
let failed = false; | ||
stream.on("close", function () { | ||
if (!failed) { | ||
res.statusCode = 204; | ||
res.end(); | ||
} | ||
}); | ||
stream.on("error", err => { | ||
throw err; | ||
failed = true; | ||
console.error(err); | ||
new HTTPResponseError(500).process(res); | ||
}); | ||
req.pipe(stream); | ||
return; | ||
@@ -150,0 +155,0 @@ } |
@@ -27,3 +27,3 @@ const crypto = require("crypto"); | ||
if (options.verbose) logger(ctx); | ||
if (options.cors) cors(ctx); | ||
if (options.cors && cors(ctx)) return; | ||
if (!options.public) auth(ctx); | ||
@@ -30,0 +30,0 @@ if (_static(ctx)) return; |
Sorry, the diff of this file is not supported yet
26131
572
122