-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
113 lines (94 loc) · 3.08 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const express = require("express");
const proxy = require("express-http-proxy");
const path = require("path");
const parser = require("body-parser");
const cors = require("cors");
const app = express();
app.use(cors());
app.set("port", process.env.PORT || 3000);
app.use(express.static("public"));
app.use(express());
app.use(parser.json());
app.get("/", function(req, res) {
res.redirect("/restaurants/");
});
app.use(
"/restaurants/:restaurantID/menu/:menu",
proxy({ target: "http://127.0.0.1:3001/", changeOrigin: true })
);
app.use(
"/restaurants/:restaurantID/menu/special",
proxy({ target: "http://127.0.0.1:3001/", changeOrigin: true })
);
app.use(
"/restaurants/:restaurantID/menu/menuCount",
proxy({ target: "http://127.0.0.1:3001/", changeOrigin: true })
);
app.get("/restaurants/:restaurantID/menu/:menu", function(req, res) {
const menuPath = path.join(__dirname, "./public/index.html");
res.sendFile(menuPath);
});
app.get("/restaurants/:restaurantID/menu/special", function(req, res) {
const menuPath = path.join(__dirname, "./public/index.html");
res.sendFile(menuPath);
});
app.get("/restaurants/:restaurantID/menu/menuCount", function(req, res) {
const menuPath = path.join(__dirname, "./public/index.html");
res.sendFile(menuPath);
});
app.use(
"/restaurants/:id/overview/",
proxy({ target: "http://127.0.0.1:3002/", changeOrigin: true })
);
app.get("/restaurants/:id/overview/", function(req, res) {
const overview = path.join(__dirname, "./public/index.html");
res.sendFile(overview);
});
app.use(
"/restaurants/:restaurantID/reservations",
proxy({ target: "http://127.0.0.1:3003/", changeOrigin: true })
);
app.get("/restaurants/:restaurantID/reservations", function(req, res) {
const reservations = path.join(__dirname, "./public/index.html");
res.sendFile(reservations);
});
app.use(
"/restaurants/:rest_id/gallery",
proxy({ target: "http://127.0.0.1:3004/", changeOrigin: true })
);
app.get("/restaurants/:rest_id/gallery", function(req, res) {
const gallery = path.join(__dirname, "./public/index.html");
res.sendFile(gallery);
});
app.use(
"/restaurants/:restaurantid/reviews",
proxy({
target: "http://127.0.0.1:3005/"
})
);
app.use(
"/restaurants/:restaurantid/reviewsummary",
proxy({
target: "http://127.0.0.1:3005/"
})
);
app.get("/restaurants/:restaurantid/reviews", function(req, res) {
const reviews = path.join(__dirname, "./public/index.html");
res.sendFile(reviews);
});
app.get("/restaurants/:restaurantid/reviewsummary", function(req, res) {
const reviews = path.join(__dirname, "./public/index.html");
res.sendFile(reviews);
});
app.listen(3000, () => {
console.log("listening on port 3000");
});
// const express = require('express');
// const bodyParser = require('body-parser');
// const path = require('path');
// const app = express();
// const PORT = 3000;
// app.use(bodyParser.json());
// app.use(bodyParser.urlencoded({ extended: true }));
// app.use('/restaurants/:restaurantId', express.static(path.join(__dirname, '../public')));
// app.listen(PORT, () => console.log(` listening to port ${PORT}`));