Skip to content

Commit

Permalink
prepare for deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
JaberHPranto committed Oct 28, 2021
1 parent 607a764 commit b06064f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node server/index.js
2 changes: 1 addition & 1 deletion client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ yarn-error.log*
yarn.lock

#env
.env
.env
18 changes: 15 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ app.use(express.json({ limit: "30mb", extended: true }));
app.use(express.urlencoded({ limit: "30mb", extended: true }));
app.use(cors());

app.get("/", (req, res) => {
res.send("Hello world");
});

//routes
app.use("/api/products", productRoutes);
Expand All @@ -42,6 +39,21 @@ app.get("/api/config/paypal",(req,res)=>res.send(process.env.PAYPAL_CLIENT_ID))
const __dirname = path.resolve()
app.use('/uploads', express.static(path.join(__dirname, './uploads')))

// for production
if (process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, '../client/build')))
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname,'../','client', 'build', 'index.html'))
})
}
else {
app.get("/", (req, res) => {
res.send("Hello world");
});
}



// error handler
app.use(notFound);
app.use(errorHandler);
Expand Down
3 changes: 2 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"type": "module",
"scripts": {
"start": "nodemon index.js"
"start": "nodemon index.js",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"keywords": [],
"author": "",
Expand Down

0 comments on commit b06064f

Please sign in to comment.