-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
45 lines (35 loc) · 1.45 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
require('dotenv').config();
require('./config/database'); // connects to db
const express = require('express');
const path = require('path'); // node module
const favicon = require('serve-favicon');
const logger = require('morgan');
const cors = require('cors');
const app = express();
// development port: 3001
// in production we'll a PORT number set in the environment variables
const PORT = process.env.PORT || 3001;
//* Config
// Logger middleware
app.use(logger('dev'));
app.use(cors({origin:["https://final-project-v997.onrender.com/"]}))
// JSON payload middleware (for data coming from frontend functions)
app.use(express.json());
// Configure both serve-favicon & static middleware
// to serve from the production 'build' folder
app.use(favicon(path.join(__dirname, 'build', 'favicon.ico')));
app.use(express.static(path.join(__dirname, 'build')));
// checks if token was sent and sets a user data on the req (req.user)
app.use(require('./config/checkToken'));
// * All other routes
app.use('/api/todos', require('./routes/api/todos'))
app.use('/api/users', require('./routes/api/users'), require('./routes/api/todos'));
// Put API routes here, before the "catch all" route
// The following "catch all" route (note the *) is necessary
// to return the index.html on all non-AJAX requests
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'))
})
app.listen(PORT, () => {
console.log(`Server is running on port: ${PORT}`);
})