forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
d3b6c090f3
commit
332f960f86
57 changed files with 2884 additions and 1972 deletions
|
@ -65,9 +65,9 @@ export class Server {
|
|||
},
|
||||
})
|
||||
this.handlers = handle
|
||||
http.createServer((req: http.IncomingMessage, res) =>
|
||||
this.answerRequest(req, res)
|
||||
).listen(port)
|
||||
http.createServer((req: http.IncomingMessage, res) => this.answerRequest(req, res)).listen(
|
||||
port
|
||||
)
|
||||
console.log(
|
||||
"Server is running on http://127.0.0.1:" + port,
|
||||
". Supported endpoints are: " + handle.map((h) => h.mustMatch).join(", ")
|
||||
|
@ -86,7 +86,7 @@ export class Server {
|
|||
"from:",
|
||||
req.headers.origin,
|
||||
new Date().toISOString(),
|
||||
path,
|
||||
path
|
||||
)
|
||||
if (this.options?.ignorePathPrefix) {
|
||||
for (const toIgnore of this.options.ignorePathPrefix) {
|
||||
|
@ -114,14 +114,11 @@ export class Server {
|
|||
|
||||
res.setHeader(
|
||||
"Access-Control-Allow-Headers",
|
||||
"Origin, X-Requested-With, Content-Type, Accept",
|
||||
"Origin, X-Requested-With, Content-Type, Accept"
|
||||
)
|
||||
res.setHeader("Access-Control-Allow-Origin", req.headers.origin ?? "*")
|
||||
if (req.method === "OPTIONS") {
|
||||
res.setHeader(
|
||||
"Access-Control-Allow-Methods",
|
||||
"POST, GET, OPTIONS, DELETE, UPDATE",
|
||||
)
|
||||
res.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, UPDATE")
|
||||
res.writeHead(204, { "Content-Type": handler.mimetype })
|
||||
res.end()
|
||||
return
|
||||
|
@ -154,7 +151,7 @@ export class Server {
|
|||
"resulted in a ",
|
||||
typeof result,
|
||||
" instead of a string:",
|
||||
result,
|
||||
result
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -162,8 +159,6 @@ export class Server {
|
|||
res.writeHead(200, { "Content-Type": handler.mimetype, ...extraHeaders })
|
||||
res.write("" + result)
|
||||
res.end()
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.error("Could not handle request:", e)
|
||||
res.writeHead(500)
|
||||
|
@ -183,8 +178,7 @@ export class Server {
|
|||
* @param path
|
||||
* @param res
|
||||
*/
|
||||
public static sendFile(path: string, res: ServerResponse){
|
||||
createReadStream(path).pipe(res);
|
||||
public static sendFile(path: string, res: ServerResponse) {
|
||||
createReadStream(path).pipe(res)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue