diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..92b9c18 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: node server/index.js \ No newline at end of file diff --git a/client/.gitignore b/client/.gitignore index 33f0714..98e58d3 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -25,4 +25,4 @@ yarn-error.log* yarn.lock #env -.env \ No newline at end of file +.env diff --git a/server/index.js b/server/index.js index 41ae403..c6242e9 100644 --- a/server/index.js +++ b/server/index.js @@ -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); @@ -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); diff --git a/server/package.json b/server/package.json index 91dd1a0..c2b37fd 100644 --- a/server/package.json +++ b/server/package.json @@ -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": "",