-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (38 loc) · 1.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
const express = require('express')
const morgan = require('morgan')
const herokuForceSsl = require('heroku-ssl-redirect')
const { join } = require('path')
require('dotenv').config()
const { NODE_ENV } = process.env
const {
searchTweetsHandler,
searchTweetsMappers,
} = require('./services/twitter')
const {
searchFlickrPhotosHandler,
searchFlickrPhotosMappers,
} = require('./services/flickr')
const app = express()
const PORT = process.env.PORT || 5001
const ASSETS = join(__dirname, 'build')
// Serve static files from ./build
app.use(morgan('combined'))
app.use(herokuForceSsl())
app.use(express.static(ASSETS))
app.get('/', (req, res) => {
res.sendFile(`${ASSETS}/index.html`)
})
app.get('/api/twitter/searchtweets', searchTweetsHandler(searchTweetsMappers))
app.get(
'/api/flickr/searchphotos',
searchFlickrPhotosHandler(searchFlickrPhotosMappers)
)
// Server listener
app.listen(PORT, err => {
if (err) {
return console.log('Something bad happened', err)
}
console.log(
`Huzzah! Express Server is listening at http://localhost:${PORT}. NODE_ENV is ${NODE_ENV}`
)
})