-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (47 loc) · 1.16 KB
/
app.js
File metadata and controls
55 lines (47 loc) · 1.16 KB
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
const express = require("express");
const fetch = require('node-fetch');
const app = express();
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', "*");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
};
app.use(allowCrossDomain);
app.use(express.json());
app.use(express.urlencoded({
extended: true
}));
var ingredients = [
{
"id": "1",
"text": "Assessments"
},
{
"id": "2",
"text": "Facecode"
},
{
"id": "3",
"text": "Hackathons"
},
];
app.get('/', function(req, res) {
console.log("GET From SERVER");
res.send(ingredients);
});
app.get('/jobs', (req,res)=>{
fetch('http://jobs.github.com/positions.json?page=1&search=code')
.then(res => res.json())
.then(json => {
res.send(json).status(200);
})
})
app.post('/', function(req, res) {
const data = Object.keys(req.body)[0];
const ingredient = JSON.parse(data);
console.log("POST From SERVER");
ingredients.push(ingredient);
res.status(200).send("Successfully posted ingredient");
});
module.exports = app;