Skip to content

Commit

Permalink
build: heroku-postbuild script || chore: change static client folder …
Browse files Browse the repository at this point in the history
…|| feat: serve on single port

Create post build script for heroku which will build react static files.
Change static client folder from ..packages/backend/public to ..packages/frontend/build
Single port for serving both static files for react and backend api on port 5000
  • Loading branch information
The-Anton committed Sep 11, 2021
1 parent 5293bcf commit 1d06df9
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 26,908 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -6,6 +6,7 @@
],
"scripts": {
"postinstall": "husky install",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false cd packages/frontend && npm install && npm run build",
"prepare": "husky install"
},
"lint-staged": {
Expand Down
1 change: 0 additions & 1 deletion packages/backend/api/auth/controller.js
@@ -1,5 +1,4 @@
const express = require("express");
const router = express.Router();
const passport = require("passport");
const auth = require("../../config/passport");
const logout = require("express-passport-logout");
Expand Down
12 changes: 6 additions & 6 deletions packages/backend/api/auth/index.js
Expand Up @@ -13,25 +13,25 @@ passport.deserializeUser(auth.deserializeUser);
passport.serializeUser(auth.serializeUser);

//Github
router.get("/auth/github", authController.authGithub);
router.get("/github", authController.authGithub);
router.get(
"/auth/github/callback",
"/github/callback",
authController.authGithub,
authController.redirect
);

//Google
router.get("/auth/google", authController.authGoogle);
router.get("/google", authController.authGoogle);
router.get(
"/auth/google/callback",
"/google/callback",
authController.authGoogleCallback,
authController.redirect
);

//linkedin
router.get("/auth/linkedin", authController.authLinkedin);
router.get("/linkedin", authController.authLinkedin);
router.get(
"/auth/linkedin/callback",
"/linkedin/callback",
authController.authLinkedin,
authController.redirect
);
Expand Down
26 changes: 8 additions & 18 deletions packages/backend/server.js
Expand Up @@ -30,7 +30,6 @@ app.use(express.json());
// sanitize Data

app.use(mongoSanitize());

// xss-clean

app.use(xss());
Expand All @@ -47,23 +46,12 @@ app.use(hpp());
// cors

app.use(cors());

app.options("*", cors());

// file Upload
app.use(fileUpload());
// set static folder
const options = {
dotfiles: "ignore",
etag: false,
extensions: ["htm", "html"],
maxAge: "1d",
redirect: false,
setHeaders: function (res, path, stat) {
res.set("x-timestamp", Date.now());
},
};
app.use(express.static(path.join(__dirname, "./public"), options));

// session
app.use(passport.initialize());
app.use(passport.session());
app.use(
Expand All @@ -75,12 +63,14 @@ app.use(
})
);

// set static folder
app.use(express.static(path.join(__dirname, "../frontend", "build")))

// Use Routes
app.use("/", auth);
app.get("*.*", express.static("./public/frontend")); // production
app.use('/api/auth', auth);

app.all("*", (req, res) => {
res.status(200).sendFile("/", { root: "./public/frontend" });
app.get("*", (req, res) => {
res.sendFile(path.join(__dirname, "../frontend", "build", "index.html"));
});

app.use(errorHandler);
Expand Down

0 comments on commit 1d06df9

Please sign in to comment.