Skip to content

Commit

Permalink
moved compression in production phase
Browse files Browse the repository at this point in the history
  • Loading branch information
Th3Wall committed Feb 11, 2021
1 parent fae0e16 commit cb5169f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"cors": "2.8.5",
"dotenv": "7.0.0",
"express": "^4.16.4",
"express-sslify": "^1.2.0",
"stripe": "6.28.0"
},
"devDependencies": {
Expand Down
9 changes: 7 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const cors = require("cors");
const bodyParser = require("body-parser");
const path = require("path");
const compression = require('compression');
const enforce = require('express-sslify');

if (process.env.NODE_ENV !== "production") require("dotenv").config();

Expand All @@ -11,13 +12,13 @@ const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
const app = express();
const port = process.env.PORT || 5000;

app.use(compression());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.use(cors());

if (process.env.NODE_ENV === "production") {
app.use(compression());
app.use(enforce.HTTPS({ trustProtoHeader: true }));
app.use(express.static(path.join(__dirname, "client/build")));

app.get("*", function (req, res) {
Expand All @@ -30,6 +31,10 @@ app.listen(port, (error) => {
console.log("Server running on port " + port);
});

app.get('/service-worker.js', (res, req) => {
res.sendFile(path.resolve(__dirname, '..', 'build', 'service-worker.js'));
})

app.post("/payment", (req, res) => {
const body = {
source: req.body.token.id,
Expand Down

0 comments on commit cb5169f

Please sign in to comment.