-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (41 loc) · 1.41 KB
/
index.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
const express = require('express')
const mongoose = require('mongoose')
const proxy = require('http-proxy-middleware')
const path = require('path')
// const controllerD = require('../David-service/server/controllers')
// const controllerB = require('../service-blake/db/controller')
// const controllerA = require('../service-aaron/server/controllers')
const app = express()
const port = 3000
app.use(express.static(path.join(__dirname, 'dist')))
const servers = [
{ route: '/reviews', location: 'http://localhost:3003/reviews' },
{ route: '/ikea', location: 'http://localhost:3007/ikea' },
{ route: '/products', location: 'http://localhost:3001/products' },
{ route: '/searchbar', location: 'http://localhost:3002/searchbar' }
]
for (server of servers) {
app.use(
server.route,
proxy({
target: server.location,
pathRewrite: (path, req) => {
return path
.split('/')
.slice(2)
.join('/')
}
})
)
}
// app.get('/ikea', (req, res) => controllerD.getAll(req, res))
// app.get('/ikeaproducts', (req, res) => controllerA.getAll(req, res))
// app.get('/reviews', (req, res) => controllerB.get(req, res))
app.listen(port, () => {
console.log(`listening on port ${port}`)
mongoose.connect('mongodb://localhost/fec', {
useNewUrlParser: true,
useUnifiedTopology: true
})
mongoose.connection.on('connected', () => console.log('connected to mongdb'))
})