Skip to content

Commit 3dbefb0

Browse files
committed
added instructions for api server
1 parent 0fc8341 commit 3dbefb0

File tree

2 files changed

+112
-2109
lines changed

2 files changed

+112
-2109
lines changed

lessons/04-core-react-concepts/A-jsx.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ You can test your app by running `npm run dev` and opening the URL shown in the
138138

139139
For this course we will use a little Fastify server I built for you. It's in the [api][api] directory. We are going to use Vite.js to proxy to this API server. This is a useful trick to do for local development if you have a separate frontend in a backend. Normally you'd have something like NGINX routing traffic to separate frontend and backend servers. For now we'll just use Vite.
140140
141-
> Note: This means you'll need to have TWO terminal windows running. One terminal for the API server (which you won't have to touch once it's running). The other terminal is is our Vite server for our web app.
141+
> Note: This means you'll need to have TWO terminal windows running. One terminal for the API server (which you won't have to touch once it's running). The other terminal is is our Vite server for our web app.
142142

143143
Add this to you vite.config.js
144144

@@ -163,7 +163,21 @@ export default defineConfig({
163163

164164
## Run the API Server
165165

166-
Open a new terminal and navigate to the `api` directory. Note that this server is _outside_ your project directory. You'll need to install the dependencies with `npm install`. After that, you can start the server by running `npm run dev`. You need both servers running at the same time. Your Vite server will intercept `api` and `public` calls and reroute them to your API server!
166+
If you didn't do this earlier in the course, download or clone [the citr-v9-project repo](https://github.com/btholt/citr-v9-project). You only need the `api` directory for the API server.
167+
168+
Open a new terminal and navigate to the `api` directory. Note that this server is _outside_ your project directory.
169+
170+
Using **Node 20 or higher**, go into the `api` directory, install the dependencies, and run the server:
171+
172+
```bash
173+
cd citr-v9-project/api
174+
npm install
175+
npm run dev
176+
```
177+
178+
The server should start on port 3000. To verify it's working, visit [http://localhost:3000/api/pizzas](http://localhost:3000/api/pizzas) and you should see the pizza JSON data.
179+
180+
You need both servers running at the same time. With the Vite proxy configuration from above, your Vite server will intercept `api` and `public` calls in the React application and reroute them to your API server!
167181

168182
Now let's add images to our Pizza.
169183

0 commit comments

Comments
 (0)