-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (29 loc) · 900 Bytes
/
app.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
const express = require('express');
const app = express();
app.use(express.json());
// const cors = require('cors');
// app.use(cors()); //comment this to understand preflight request
app.use((req, res, next) => {
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Headers', 'Content-Type');
next();
})
app.options("/testPOST", (req, res) => {
console.log("at preflight");
// res.set('Access-Control-Allow-Origin', '*');
// res.set('Access-Control-Allow-Headers', 'Content-Type');
res.status(204).send();
});
app.get('/testGET', (req, res) => {
// console.log(req.body);
res.json({
status: "success"
})
})
app.post('/testPOST', (req, res) => {
// console.log(req.body);
res.json({ status: "success" });
})
app.listen(process.env.PORT || 4000, () => {
console.log("started the server at port 4000 .....");
})