-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (26 loc) · 1017 Bytes
/
server.js
File metadata and controls
33 lines (26 loc) · 1017 Bytes
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
require('dotenv').config();
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3001;
const db = require("./models");
const path = require("path");
const enforceAuth = require('./auth/enforce-auth.js');
// configure express
require('./middleware/express-config')(app);
// make sure static files are available for react
app.use(express.static('client/build'));
// serve api routes but require authentication
app.use('/api', enforceAuth, require("./routes/apiRoutes.js"));
//dont enforce auth
// app.use('/api', require("./routes/apiRoutes.js"));
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
//implement error handler that will respond with JSON and a 500 status code
app.use(require('./middleware/errorHandler'));
//changing force to true will clear the database
db.sequelize.sync({force: false}).then(
app.listen(PORT, function () {
console.log("listening on http://localhost:" + PORT);
})
);