-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (43 loc) · 1.42 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
// Disregard many of the comments, they are mostly notes to myself
// require('dotenv').config()
const express = require('express')
// const logger = require('morgan')
const mongoose = require('mongoose')
const googleRouter = require('./routes/google')
const cors = require('cors')
const routes = require("./routes");
const app = express()
// setting the URI for the database (default to localhost if it's not defined) & connecting it
/*
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost/auth'
*/
const MONGODB_URI = process.env.MONGODB_URI || "mongodb://localhost/favorites"
const PORT = process.env.PORT || 3001
mongoose.set('useCreateIndex', true)
mongoose.connect(MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true }, (err) => {
console.log(err || `Connected to MongoDB.`)
})
app.use(express.static(`${__dirname}/client/build`))
app.use(cors())
// app.use(logger('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: true }));
//GET method for API
app.get('pathto/API', (req, res) => {
res.json({message: ""})
})
// calling in routes
/*
app.use('/api', favRoutes)
app.use("/", favRoutes);
app.use("/api/favorite", favRoutes);
*/
app.use(routes);
app.use('/api/google', googleRouter)
// Route for default homepage
app.use('*', (req, res) => {
res.sendFile(`${__dirname}/path/to/defaulthomepage`)
})
app.listen(PORT, (err) => {
console.log(err || `Server running on port ${PORT}.`)
})