-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
44 lines (39 loc) · 1.32 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
var compression = require('compression');
var passport = require("./client/config/passport");
var compression = require('compression');
const express = require("express");
var session = require("express-session");
const path = require("path");
const PORT = process.env.PORT || 8080;
var db = require("./client/models");
const app = express();
app.use(compression());
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Serve up static assets (usually on heroku)
if (process.env.NODE_ENV === "production") {
app.use(express.static("client/build"));
}
// App session
app.use(session({ secret: "keyboard cat", resave: true, saveUninitialized: true }));
app.use(passport.initialize());
app.use(passport.session());
// Send every request to the React app
require("./client/src/api-routes.js")(app);
// Define any API routes before this runs
app.get("*", function(req, res) {
res.sendFile(path.join(__dirname, "./client/build/index.html"));
});
db.sequelize.sync().then(function() {
app.listen(PORT, function() {
console.log(`🌎 ==> API server now on port ${PORT}!`);
});
});
function shouldCompress (req, res) {
if (req.headers['x-no-compression']) {
// don't compress responses with this request header
return false
}
// fallback to standard filter function
return compression.filter(req, res)
}