-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (47 loc) · 1.27 KB
/
app.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
const express = require('express')
const app = express()
require('dotenv').config()
const {PORT} = require('./config/default')
const path = require('path')
const cors = require('cors')
const googleRoutes = require('./route/google')
app.use(cors())
app.use(express.json())
app.use(express.urlencoded({extended: true}))
app.get('/api/ping', (req, res) => {
res.send('pong')
})
app.get('/api/technicians', (req, res) => {
const dummyData = [
{
name: 'Sally Doe',
address_1: 'Park City, UT',
address_2: 'Heber City, UT',
address_3: 'Midway, UT',
},
{
name: 'John Doe',
address_1: 'Park City, UT',
address_2: 'Logan, UT',
},
{
name: 'Jordan Doe',
address_1: 'Park City, UT',
address_2: 'Antelope Island, UT',
address_3: 'Ogden, UT',
},
]
res.status(200).json(dummyData)
})
app.use('/api/google', googleRoutes)
const isProduction = () => {
return process.env.NODE_ENV === 'production'
}
if (isProduction()) {
app.use(express.static(path.join(__dirname, 'client/build')))
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/client/build/index.html'))
})
}
const port = isProduction() ? PORT : 3001
app.listen(port, () => console.log(`Server is running on port ${port}!`))