Build Websites and Apps with AI
ProjectBeginner 30 min· Project: coffee shop website · 11 of 21

Deploy the site for free

Build the Brew & Bean site for production, push it to GitHub and deploy it to a free host. You will fix single-page routing so /menu works on refresh, test the live site on your phone, learn how updates work and how to debug a failed deploy.

Your site works on your laptop, but nobody else can see it. In this lesson you put the Brew & Bean website on the internet for free, with a public link you can send to friends, add to your resume and open in an interview. You will build the site for production, push the code to GitHub, deploy it to a free host, fix the one problem every single-page app has (refreshing on /menu), and learn how to update it.

Start from: the project at the end of *Make it responsive, accessible and fast*, with all changes committed. You also need a free GitHub account (github.com).

What deployment means

When you run npm run dev, Vite serves your site only on your own computer. To share it you need two things:

1. A build. npm run build turns your React code into a folder called dist with plain HTML, CSS and JavaScript files. These are static files: no server code runs. Any host that can serve files can serve your site. 2. A host. A company's computers that serve those files to anyone who asks, at a public address.

Because our site has no backend yet, it is a static site. That is why hosting can be free. In the last project lesson of this track we deploy the API and connect the two.

Step 1: Build it locally first

Always build on your own computer before you deploy. If the build fails here, it will fail on the host too, and you will see the error faster.

Terminal
npm run build
npm run preview

build creates the dist folder. preview serves it locally so you can click through the real production version.

Typical output (numbers will differ)
vite v8.x building client environment for production...
✓ 37 modules transformed.
dist/index.html                   0.72 kB
dist/assets/index-xxxx.css        5.95 kB
dist/assets/Cart-xxxx.js          4.63 kB
...
✓ built in 220ms

  ➜  Local:   http://localhost:4173/

Open the preview address and click through the site: Home, Menu, add an item, Cart, place a demo order. Fix anything broken before moving on.

Two things to know about dist: it is generated, so it should not be committed to Git (Vite's .gitignore already excludes it), and every deploy rebuilds it from your source code.

Step 2: Fix single-page app routing

Our site has only one real HTML file, index.html. The router shows the right page by reading the address. That works when you click links. But if someone opens https://your-site/menu directly, or refreshes the Menu page, the host looks for a file called menu, finds nothing and shows its own 404 page.

The fix is a rewrite rule: "for any address, send index.html and let React decide". Every host has its own way to say this. Create the file below. Vite copies everything in public/ to dist as it is.

public/_redirects
/*  /index.html  200

A rule for Netlify. The first part is the pattern (every path), the second is the file to send, 200 means it is a rewrite (the address bar does not change).

One rule, different hosts

HostHow it handles single-page apps
NetlifyAdd the public/_redirects file above
VercelAdd a vercel.json file with a rewrite (shown below)
Cloudflare PagesSingle-page apps usually work without extra files if you have no 404.html; check the current docs
GitHub PagesNo rewrite rules. You need extra workarounds (a copied 404.html or a hash router), so choose another host for this project
vercel.json (only if you use Vercel)
{
  "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
}

Put it in the project root, next to package.json.

Step 3: Put the code on GitHub

Modern hosts deploy straight from a GitHub repository: you push code, they build and publish it. This also gives you a backup and a public portfolio.

Create the repository

  1. 1Commit your latest changes in the terminal (see the commands below).
  2. 2On github.com click New repository. Name it brew-and-bean. Leave it empty: don't tick the options to add a README, .gitignore or licence. Click Create.
  3. 3GitHub shows a page with commands. Copy the two lines that start with git remote add origin and git push, or use the ones below with your own username.
  4. 4Run them in the terminal. Refresh the GitHub page: you should see your files.
Terminal
git add .
git commit -m "Add redirects for deployment"
git branch -M main
git remote add origin https://github.com/[your-username]/brew-and-bean.git
git push -u origin main

Replace [your-username]. If GitHub asks you to sign in, follow the browser window it opens.

Public means public

Check that no secrets are in your repository before you push. Today there are none, but get into the habit: never commit passwords, API keys or .env files. A public repository is visible to everyone, and bots scan GitHub for leaked keys.

Step 4: Deploy for free

Several hosts offer a free plan for static sites. We show Netlify because its steps are simple, and then list alternatives. Plans and limits change, so check the host's pricing page. Note that some free plans are for personal, non-commercial use only, which matters if you later build a site for a real shop.

Deploy on Netlify

  1. 1Create a free account at netlify.com (signing up with GitHub is easiest).
  2. 2Choose to add a new site and import an existing project from GitHub. Allow access to your brew-and-bean repository when asked.
  3. 3Netlify detects Vite. Check the settings: build command npm run build, publish directory dist.
  4. 4Click Deploy. Watch the log. It installs packages, runs the build and publishes the result. It usually takes about a minute or two.
  5. 5When it finishes, Netlify shows a public address ending in netlify.app. Open it.
  6. 6In the site settings you can change the random name to something readable, for example brew-and-bean-yourname, if it is free.
What the deploy log looks like (times and wording will differ)
12:01:10 PM: Build command from Netlify app: npm run build
12:01:25 PM: ✓ built in 4.2s
12:01:27 PM: Site is live

Alternatives

OptionGood forNotes
NetlifySimple Git-based deploys and a drag-and-drop option for the dist folderFree plan with limits; check the pricing page
VercelGit-based deploys; very common for React and Next.js projectsNeeds vercel.json for the rewrite; its free plan is meant for personal use, so read the terms
Cloudflare PagesFree static hosting on a large networkCheck the current docs; Cloudflare is changing how its products are organised

Step 5: Test the live site

Done when

  1. Open the live address on your phone, not only on your laptop. Is it readable and fast?
  2. Click through Home, Menu, add items, Cart and place a demo order.
  3. Open the live address followed by /menu directly in a new tab. It must load the Menu page (this tests the rewrite).
  4. Refresh on /cart. It must still work.
  5. Open an address that doesn't exist, such as /coffee. You should see your own "Page not found" page.
  6. Check the browser tab title and the favicon.
  7. Open DevTools (F12) and look at the Console. No red errors.
  8. Run Lighthouse on the live URL.

Update the site

From now on, deploying is just Git. Change a file, commit and push. The host notices the push, rebuilds and publishes the new version. If the build fails, the old version stays online, which is a nice safety net.

Terminal
git add .
git commit -m "Change opening hours"
git push

Wait for the host to finish the build, then refresh the live site. You may need a hard refresh (Ctrl+Shift+R) to skip the browser cache.

When the deploy fails

Troubleshooting

SymptomLikely causeFix
Build fails: Could not resolve './components/header.jsx'File name capitals differ from the import. Windows and macOS often ignore the difference but the host's Linux build does notMake the file name and the import match exactly. Run git ls-files to see the name Git has
Build fails with a Node version errorThe host uses an older Node than Vite needsSet the Node version in the host's settings (Vite needs 20.19 or newer, or 22.12 or newer) and redeploy
Live site is a blank pageA JavaScript error, or wrong base pathOpen the console. For this project you should not need to change base in vite.config.js
Live site shows 404 on /menuMissing rewrite ruleAdd public/_redirects (Netlify) or vercel.json (Vercel), commit, push
Build works on your PC but not on the hostA file is not committed (for example ignored by .gitignore)Run git status and git ls-files and compare with your folders
Old version still showingBrowser cacheHard refresh or open a private window
Prompt · Debug a failed deploy
My React (Vite) site builds on my computer but fails when I deploy it to [Netlify / Vercel / Cloudflare Pages]. This is the build log from the host:

<log>
[paste the part of the log around the first error]
</log>

My build command is `npm run build` and my publish directory is `dist`.

Explain what went wrong in plain English, list the 2 or 3 most likely causes in order, and tell me how to check each one before changing anything.

What to expect: Read the first error in the log, not the last. The last lines are often just consequences. Check the cause yourself before you accept the fix.

Looking ahead: environment variables

In the API lessons you will connect this site to a backend with a setting such as VITE_API_URL. Vite exposes only variables whose names start with VITE_ to the browser, and you set them in the host's settings, not in committed files. Remember this rule: anything in a front-end build is public. Anyone can open DevTools and read it. So never put a secret key (a database password, a paid API key) in a VITE_ variable. Secrets belong on the server.

Share it

Add the live link to the top of a short README.md in your repository, to your resume and to your GitHub profile. In an interview you can say: "I planned it with a spec, built it in small steps with AI assistance, reviewed and tested every step, made it responsive and accessible, and deployed it." That is a strong answer. Be ready to explain any file in the project; if you can't, ask the AI to explain it and write the explanation in your own words.

Try it: Write a README

Add a README.md with: the live link, a one-paragraph description, the tech used, how to run it locally (npm install, npm run dev) and a list of what you would build next. Commit, push and see it appear on your GitHub page.

Try it: Stretch: add a custom domain or a second deploy

Deploy the same repository to a second host (for example Vercel or Cloudflare Pages) and compare how long the setup took and what each dashboard shows. Or, if you own a domain, connect it using your host's custom domain settings.

Key takeaways

  1. npm run build makes a dist folder of static files; always build and preview locally before deploying.
  2. A single-page app needs a rewrite rule (public/_redirects on Netlify, vercel.json on Vercel) so /menu works on refresh.
  3. Push to GitHub, connect the repository to a host, and every push redeploys the site.
  4. Match file name capitals exactly: Windows may forgive mistakes that the host's Linux build will not.
  5. Everything in a front-end build is public; never put secrets in the browser code.
  6. Free plans have limits and terms, so read them, especially for commercial sites.

Check yourself

Finishing the quiz marks the lesson as done.

1. A user refreshes https://your-site/menu and sees the host's 404 page. What is the cause and fix?

2. Why should you run npm run build on your own computer before deploying?

3. Your build passes on Windows but the host reports it cannot resolve './components/header.jsx', while the file is Header.jsx. Why?

4. Which is safe to put in a VITE_ environment variable in a front-end app?

5. Why is dist not committed to Git?

Saved on this device. Create a free account to keep it on every device.

Practise this with Sam

A real mock interview, out loud, with an honest scorecard. Free to start.

Start free