-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
78 lines (63 loc) · 2.33 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
const express = require('express')
const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')
const path = require('path')
const port = process.env.PORT || 3000
const apiKeyContainer = require('./src/config/apiKey')
process.env.apiKey = apiKeyContainer.vinMonopoletAPIKeyPrimary
const fetchVinmonopoletfilePath = path.join(__dirname, '/src/components/fetchVinmonopolet.js')
const fetchVinmonopolet = require(fetchVinmonopoletfilePath)
const fetchHomeStorePath = path.join(__dirname, '/src/components/fetchHomeStore.js')
const fetchHomeStore = require(fetchHomeStorePath)
const app = express()
const config = require('./webpack.config.js')
const compiler = webpack(config)
app.get('/homestore', (req, res) => {
if (!req.query.id) {
return res.send({
error: 'You must provide an id in the query! IE: localhost:3000/vinmonopolet?id=blabla. (in the future Marty)'
})
}
const searchTerm = req.query.id
fetchHomeStore(searchTerm, (error, storeData) => {
if (error) {
return res.send({ error })
}
res.send({
storeData: storeData,
storeID: req.query.id,//note this is the query field in the browser, whatever is typed after ?id=blabla inthe browser
})
})
})
app.get('/vinmonopolet', (req, res) => {
if (!req.query.city) {
return res.send({
error: 'You must provide a city in the query! IE: localhost:3000/vinmonopolet?city=blabla. (in the future Marty)'
})
}
const searchTerm = req.query.city
fetchVinmonopolet(searchTerm, req.query.getallstores, (error, storeData) => {
if (error) {
return res.send({ error })
}
res.send({
storeData: storeData,
cityFromBrowserQuery: req.query.city//note this is the query field in the browser, whatever is typed after ?address=blabla inthe browser
})
})
})
// Tell express to use the webpack-dev-middleware and use the webpack.config.js
// configuration file as a base.
app.use(
webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
})
);
// Serve the files on port 3000.
app.listen(3000, function () {
console.log('Server is up on port 3000.\n');
})
// // Changing above for heroku deployment
// app.listen(port, function () {
// console.log(`Server is up on port ${port}\n`);
// })