-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
46 lines (35 loc) · 1.17 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
require('dotenv').config( )
const express = require('express')
const logger = require('morgan')
const mongoose = require('mongoose')
const usersRoutes = require('./routes')
const app = express()
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost/shoestring'
const PORT = process.env.PORT || 3001
//This is for the Plaid
const {
receivePublicToken,
getTransactions
} = require("./controllers/controller");
// Get the public token and exchange it for an access token
app.post("/auth/public_token", receivePublicToken);
// Get Transactions
app.get("/transactions", getTransactions);
mongoose.set('useCreateIndex', true)
mongoose.connect(MONGODB_URI, { useNewUrlParser: true }, (err) => {
console.log(err || `Connected to MongoDB.`)
})
app.use(express.static(`${__dirname}/client/build`))
app.use(logger('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: true }));
app.get('/api', (req, res) => {
res.json({message: "API root"})
})
app.use('/api/users', usersRoutes)
app.use('*', (req, res) => {
res.sendFile(`${__dirname}/client/build/index.html`)
})
app.listen(PORT, (err) => {
console.log(err || `Server running on port ${PORT}.`)
})