Adding a React frontend to your Eventonica API

Prerequisites

Primary Goals

Overview/Instructions

In this project, you’ll create a React frontend for your Eventonica API. You will have less than 2 days, so be aware of your pace.

Step 1: Requirements

You will be using the same Express API from your existing Eventonica project. You can use the same styling or make it better, but it does not have to support all the features of Part 6. Here are the features that must be included:

If you want to implement the rest of them, consider it an optional bonus.

Step 2: Set up React App

Note: when following these steps you will now have TWO SERVERS running:
  1. The first one is your existing Express server that talks to the database and serves your API routes
  2. The second will be a server that just serves React assets and enables hot reloading of changes - and it will proxy calls to your API server to avoid CORS isuses.

For this project, we’ll use create-react-app to set up the React frontend. There are many possible ways to set up React, and we’re going to describe one specific setup that will make it easy for you to deploy your project later.

Here’s an example of what package.json might look like now:

{
  "name": "eventonica-react",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.8.3",
    "react-dom": "^16.8.3",
    "react-scripts": "2.1.5"
  },
  "scripts": {
    "start": "PORT=3001 react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "proxy": "http://localhost:3000"
}

Note: the “proxy” key is OUTSIDE “browerslist” as a top-level config. If you put it inside “browserslist” it will neither work nor complain that your config is wrong

Step 3: Write the React code

Troubleshooting

When trying to make an API request, I get a CORS error

You are making a request to your Express server directly. Because it’s on a different port, browsers block this for security reasons. If you set up the proxy as above you should just make fetch requests to /path (no server/port listed) and it will proxy it correctly so you won’t have issues.

My API request gets a 404

Supplemental Materials

Challenges