prepares for deployment on heroku

This commit is contained in:
Ruidy Nemausat 2020-04-23 14:28:14 +02:00
parent 268314537a
commit 3f75445d0d
6 changed files with 20 additions and 37 deletions

View file

@ -5,39 +5,13 @@
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<meta name="description" content="Doo & Loo's shopping list" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React Redux App</title>
<title>Shop'it</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

View file

@ -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"
}
}

View file

@ -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() {
<Label for="item">Add an Item</Label>
<Input
type="text"
name="name"
// name="name"
id="item"
onChange={handleChange}
/>

View file

@ -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 }),
},
});

View file

@ -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"
},

View file

@ -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(