Unit 3 of 3 · BCA Sem 4

Unit 3: Integration and deployment

Web Programming-II notes · PTU syllabus (UGDSE303)

3 min read5 topics8 exam questions
On this page
  1. Unit summary
  2. Connecting frontend and backend, and CORS
  3. Form submission and API requests
  4. JWT authentication
  5. Project structure and best practices
  6. Deployment and environment variables
  7. Key terms
  8. Quick revision
  9. Important questions

Unit summary

The final step is joining the React frontend to the Node/Express backend, securing it, and putting it online. This unit covers connecting the two, CORS, API requests from forms, JWT authentication and login/signup flows, full-stack project structure, and deployment with environment variables.

After this unit you can

  • Connect a React frontend to an Express API and handle CORS
  • Submit forms to an API and handle responses and errors
  • Implement JWT-based login and signup
  • Structure, configure and deploy a full-stack project

PTU syllabus topics

  • Connecting React frontend with Node/Express API
  • CORS
  • form submission and API requests
  • JWT authentication
  • login/signup workflow
  • full-stack project structure and best practices
  • deployment to Netlify/Render/Vercel/Heroku
  • environment variables
ProcessFull-stack request with JWT
  1. 1Login

    User sends credentials

  2. 2Issue token

    Server returns a signed JWT

  3. 3Call API

    Client sends the token with requests

  4. 4Verify

    Server checks the token

  5. 5Respond

    Returns protected data

1

Topic 1

Connecting frontend and backend, and CORS

The React app (for example on localhost:3000) calls the API (on localhost:5000) with fetch or axios. Because they run on different origins, the browser blocks the requests unless the server allows them — CORS (Cross-Origin Resource Sharing).

javascriptconst cors = require("cors");
app.use(cors({ origin: "http://localhost:3000" }));
2

Topic 2

Form submission and API requests

jsxasync function handleSubmit(e) {
  e.preventDefault();
  const res = await fetch("/api/tasks", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ title }),
  });
  if (!res.ok) setError("Could not save");
}
3

Topic 3

JWT authentication

ProcessLogin with JWT
  1. 1

    User submits email and password

  2. 2

    Server checks the hashed password

    bcrypt.compare

  3. 3

    Server signs a JWT

    jwt.sign({ id }, SECRET, { expiresIn: "1h" })

  4. 4

    Client stores the token

  5. 5

    Client sends it on each request

    Authorization: Bearer <token>

  6. 6

    Middleware verifies it

    jwt.verify before protected routes

A JWT (JSON Web Token) has three parts — header, payload and signature — and lets the server confirm a user's identity without storing sessions. Passwords must be hashed (bcrypt) at signup.

4

Topic 4

Project structure and best practices

FolderContents
client/React app: components, pages, services
server/routesExpress route files
server/controllersRequest-handling logic
server/modelsDatabase schemas (Mongoose/SQL)
server/middlewareAuth, error handling
.envSecrets and configuration (never committed)

Best practices: validate input on the server, handle errors centrally, keep secrets in environment variables, and use Git.

5

Topic 5

Deployment and environment variables

  • Frontend: build with npm run build and deploy to Netlify or Vercel.
  • Backend: deploy to Render, Railway or a similar host; use a cloud database (MongoDB Atlas).
  • Environment variables (process.env.MONGO_URI, JWT_SECRET) keep configuration out of the code and differ between development and production.

Key terms

CORS
Browser rule controlling cross-origin requests
JWT
A signed token proving a user's identity
bcrypt
A library for hashing passwords
Environment variable
Configuration stored outside the code
Deployment
Making an application available online

Quick revision

  • Enable CORS on the server for the frontend origin.
  • Send JSON with Content-Type: application/json.
  • JWT: sign on login, send as Bearer token, verify in middleware.
  • Secrets in .env; frontend to Netlify/Vercel, backend to Render.

Important exam questions

Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).

Short-answer questions

  1. Q1.What is CORS and why is it needed?
  2. Q2.What are the three parts of a JWT?
  3. Q3.Why should passwords be hashed?
  4. Q4.What are environment variables used for?
  5. Q5.Name two platforms for deploying a React app.

Long-answer questions

  1. Q1.Explain how a React frontend communicates with an Express backend, including CORS.
  2. Q2.Explain JWT-based authentication with a login and signup workflow.
  3. Q3.Describe the structure and deployment of a full-stack MERN application.

Stuck on this unit?

Message SBS on WhatsApp for help with Web Programming-II, or to ask about studying BCA at Synetic.

WhatsApp us