-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
server.js
64 lines (53 loc) · 1.11 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const express = require('express');
const router = express.Router();
const path = require('path');
const bodyParser = require('body-parser');
const port = 8000;
const app = express();
app.use(bodyParser.json());
router.get('/',function(req,res){
res.sendFile(path.join(__dirname+'/index.html'));
});
app.use('/', router);
const orders = [
{
id: 1,
item: "Television",
units: 1,
price: 2345.67
},
{
id: 2,
item: "Washing Machine",
units: 3,
price: 23.34
},
{
id: 3,
item: "Laptop",
units: 1,
price: 23455.34
}
];
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "http://localhost:9000");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
res.header(
"Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE"
);
res.header("Access-Control-Allow-Credentials",true);
next();
});
app.get('/orders', (req, res) => {
console.log('Returning orders');
res.send(orders);
});
app.put('/orders', (req, res) => {
console.log('updating orders');
res.send(orders);
});
app.listen(port);