forked from fponcedeleon/fetch-me
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (33 loc) · 941 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const express = require("express");
const app = express();
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
if (req.method === "OPTIONS") {
res.header("Access-Control-Allow-Methods", "GET PATCH DELETE POST");
return res.status(200).json({});
}
next();
});
/** Routes */
app.post("/fetch-me", (req, res) => {
// Analyze your request / mutate your response.
console.log("\n\n", req.headers, "\n\n");
return res.status(499).json({
data: req.headers,
cookies: req.cookies,
message: "Intentional error to prevent further requests",
});
});
app.get("/", (req, res) => {
res.status(200).send({ success: true });
});
/** Error handling */
app.use((req, res, next) => {
const error = new Error("not found");
return res.status(404).json({
message: error.message,
});
});
module.exports = app;