forked from devslopes-learn/simple-express-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (41 loc) · 1.06 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
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
//Allow all requests from all domains & localhost
app.all('/*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "POST, GET");
next();
});
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
var ingredients = [
{
"id": "234kjw",
"text": "Eggs"
},
{
"id": "as82w",
"text": "Milk"
},
{
"id": "234sk1",
"text": "Bacon"
},
{
"id": "ppo3j3",
"text": "Frog Legs"
}
];
app.get('/ingredients', function(req, res) {
console.log("GET From SERVER");
res.send(ingredients);
});
app.post('/ingredients', function(req, res) {
var ingredient = req.body;
console.log(req.body);
ingredients.push(ingredient);
res.status(200).send("Successfully posted ingredient");
});
app.listen(6069);