From 3f75445d0d51ddab3c5d7b305f712c29e7c77f52 Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Thu, 23 Apr 2020 14:28:14 +0200 Subject: [PATCH] prepares for deployment on heroku --- client/public/index.html | 30 ++--------------------- client/public/manifest.json | 6 ++--- client/src/components/ItemModal/index.jsx | 4 +-- client/src/store/itemSlice.js | 6 ++--- package.json | 1 + server.js | 10 ++++++++ 6 files changed, 20 insertions(+), 37 deletions(-) diff --git a/client/public/index.html b/client/public/index.html index 430b58f..29d5793 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -5,39 +5,13 @@ - + - - - React Redux App + Shop'it
- diff --git a/client/public/manifest.json b/client/public/manifest.json index 2f2be64..417828b 100644 --- a/client/public/manifest.json +++ b/client/public/manifest.json @@ -1,6 +1,6 @@ { - "short_name": "React App", - "name": "Create React App Sample", + "short_name": "Shop'it", + "name": "Shop'it | Doo & Loo's shopping list", "icons": [ { "src": "favicon.ico", @@ -22,4 +22,4 @@ "display": "standalone", "theme_color": "#000000", "background_color": "#ffffff" -} +} \ No newline at end of file diff --git a/client/src/components/ItemModal/index.jsx b/client/src/components/ItemModal/index.jsx index eba914c..7d09d48 100644 --- a/client/src/components/ItemModal/index.jsx +++ b/client/src/components/ItemModal/index.jsx @@ -1,4 +1,5 @@ import React, { useState } from "react"; +import { useDispatch } from "react-redux"; import { Button, Modal, @@ -10,7 +11,6 @@ import { Input, } from "reactstrap"; import { addItemAsync } from "../../store/itemSlice"; -import { useDispatch } from "react-redux"; const useStyles = () => ({ button: { @@ -46,7 +46,7 @@ export default function ItemModal() { diff --git a/client/src/store/itemSlice.js b/client/src/store/itemSlice.js index 8d95add..ffa456b 100644 --- a/client/src/store/itemSlice.js +++ b/client/src/store/itemSlice.js @@ -18,10 +18,8 @@ export const itemSlice = createSlice({ ...state, items: [action.payload, ...state.items], }), - deleteItem: (state, action) => ({ - ...state, - items: state.items.filter((i) => i._id !== action.payload), - }), + deleteItem: (state, action) => + state.items.filter((i) => i._id !== action.payload), setItemsLoading: (state) => ({ ...state, loading: true }), }, }); diff --git a/package.json b/package.json index 34be6c5..8ac4191 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "client": "npm start --prefix client", "client-install": "npm install --prefix client", "dev": "concurrently \"npm run server\" \"npm run client\"", + "build": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client", "test": "jest", "test:watch": "npm run test -- --watch" }, diff --git a/server.js b/server.js index 489aacb..6875149 100644 --- a/server.js +++ b/server.js @@ -1,5 +1,6 @@ import express from "express"; import mongoose from "mongoose"; +import path from "path"; import moment from "moment"; import { MONGO_URI } from "./config/keys.js"; import items from "./routes/api/items.js"; @@ -22,6 +23,15 @@ app.use(express.json()); // Register routes app.use("/api/items/", items); +// Serve static assets in Production + +if (process.env.NODE_ENV === "PRODUCTION") { + app.use(express.static("client/build")); + app.get("*", (req, res) => { + res.sendFile(path.resolve(__dirname, "client", "build", "index.html")); + }); +} + // Starts server app.listen(PORT, () => console.log(