-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
92 lines (69 loc) · 3.02 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Get dependencies
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
const app = express();
const toppings = [
{value: 'Berries', img: '../assets/berries.png', extraData:{price: 5}},
{value: 'Brocoli', img: '../assets/brocoli.png', extraData:{price: 2}},
{value: 'Camamber', img: '../assets/camamber.png', extraData:{price: 5}},
{value: 'Cheese', img: '../assets/cheese.png', extraData:{price: 3}},
{value: 'Chilli', img: '../assets/chilli.png', extraData:{price: 3}},
{value: 'Garlic', img: '../assets/garlic.png', extraData:{price: 1}},
{value: 'Ginger', img: '../assets/ginger.png', extraData:{price: 2}},
{value: 'Lobster', img: '../assets/lobster.png', extraData:{price: 10}},
{value: 'Mashrooms', img: '../assets/mashrooms.png', extraData:{price: 5}},
{value: 'Olives', img: '../assets/olives.png', extraData:{price: 2}},
{value: 'Peperoni', img: '../assets/peperoni.png', extraData:{price: 7}},
{value: 'Pepper', img: '../assets/pepper.png', extraData:{price: 4}},
{value: 'Pickles', img: '../assets/pickles.png', extraData:{price: 3}},
{value: 'Shampinion', img: '../assets/shampinion.png', extraData:{price: 5}},
{value: 'Salad', img: '../assets/salad.png', extraData:{price: 4}},
{value: 'Shrimp', img: '../assets/shrimp.png', extraData:{price: 6}},
{value: 'Tomato', img: '../assets/tomato.png', extraData:{ price: 3}},
{value: 'Nana', img: '../assets/nana.png', extraData:{price: 3}},
{value: 'Cherri', img: '../assets/cherri.png', extraData:{price: 5}},
{value: 'Green', img: '../assets/green.png', extraData:{price: 4}},
{value: 'Oyister', img: '../assets/oyister.png', extraData:{price: 4}}
];
const sizes = [
{value: 'Small', img: '../assets/pizza-small.png', extraData:{price: 10}},
{value: 'Medium', img: '../assets/pizza-medium.png', extraData:{price: 15}},
{value: 'Large', img: '../assets/pizza-large.png', extraData:{price: 20}},
{value: 'Extra large', img: '../assets/pizza-extra.png', extraData:{price: 25}}
];
// Enable CORS
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
// Parsers for POST data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Point static path to dist
app.use(express.static(path.join(__dirname, 'dist')));
app.get('/sizes', (req,res) => {
res.send(sizes);
})
app.get('/toppings', (req,res) => {
res.send(toppings);
})
// Catch all other routes and return the index file
app.get('*', (req, res) => {
res.send('404')
});
/**
* Get port from environment and store in Express.
*/
const port = process.env.PORT || '3000';
app.set('port', port);
/**
* Create HTTP server.
*/
const server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port, () => console.log(`API running on localhost:${port}`));