-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
38 lines (29 loc) · 1.16 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
const express = require('express')
const path = require('path')
const favicon = require('serve-favicon')
const logger = require('morgan')
const cors = require('cors')
// always require and configure near the top
require('dotenv').config()
require('./config/database')
const app = express()
// comes from .env file or use 3001
const PORT = process.env.PORT || 3001
app.use(logger('short'))
app.use(express.json())
app.use(cors({ origin: process.env.CLIENT_ORIGIN || `http://localhost:3000` }))
app.use(require('./config/checkToken'))
// configure both the server-favicon and the static middleware
// to server from the production build folder
// app.use(favicon(path.join(__dirname, 'build', 'favicon.ico')))
// telling our express app to use this directory for our static assets
// app.use(express.static(path.join(__dirname, 'build')))
app.use('/api/users', require('./routes/api/users'))
app.use('/api/expenses', require('./routes/api/expenses'))
app.use('/api/income', require('./routes/api/income'))
// app.get('/*', (req, res) => {
// res.sendFile(path.join(__dirname, 'build', 'index.html'))
// })
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`)
})