This project is a web-based recipe management application with user authentication and admin functionality. It allows users to view, add, update, delete, and search recipes. Admins have additional capabilities to manage ingredients. The frontend is built using HTML, CSS, and JavaScript, and communicates with a backend REST API built in Java.
You will be working on the frontend of this application.
Your work will primarily be within the following folders:
src/main/resources/public/frontend/
├── login/
├── register/
├── recipe/
└── ingredients/
The backend runs on: http://localhost:8081/
- If the backend is running, make sure you are not running the automated tests at the same time.
- Styling via CSS is optional and will not be graded.
📂 Location: frontend/register/
Files:
register-page.html
register-page.js
Requirements:
- Registration form should include:
- Username, Email, Password, Repeat Password fields
- Submit button with ID
register-button
- JS should:
- Validate that all inputs are filled
- Ensure password and repeated password match
- Create a registration object and send a POST request to
http://localhost:8081/register
- On success: redirect to login page
- On failure: show an alert
📂 Location: frontend/login/
and frontend/recipe/
Files:
login-page.html
,login-page.js
recipe-page.html
,recipe-page.js
Requirements:
-
Login form should include username and password fields
-
JS should:
- Create a login request with
username
andpassword
- Send a POST request to
http://localhost:8081/login
- On success:
- Parse the response (token and admin flag separated by space)
- Store token in
sessionStorage
underauth-token
- Store admin flag under
is-admin
- Redirect to the recipe page
- On failure: show an alert
- Create a login request with
-
Logout logic (in
recipe-page.js
) should:- Send POST request to
/logout
with auth token - Clear
sessionStorage
keys - Redirect to login page
- Send POST request to
📂 Location: frontend/recipe/
Files:
recipe-page.html
recipe-page.js
Requirements:
- Add the following elements:
- Add Recipe: name input, instructions input, add button (
add-recipe-submit-input
) - Update Recipe: name input, new instructions input, update button
- Delete Recipe: name input, delete button
- Search bar: input + button
- Recipe list container (ID:
recipe-list
) - Admin-only link (ID:
admin-link
) — initially hidden
- Add Recipe: name input, instructions input, add button (
-
On page load, call:
getRecipes()
to load all recipesdisplayAdminLink()
to toggle admin section visibility
-
Implement:
addRecipe()
: POST/recipes
with name + instructionsupdateRecipe()
: PUT/recipes/{id}
with new instructionsdeleteRecipe()
: DELETE/recipes/{id}
searchRecipes()
: filter recipes locally based on name- All requests must use:
headers: { "Authorization": "Bearer " + sessionStorage.getItem("auth-token") }
- After each action, refresh the list dynamically
📂 Location: frontend/ingredients/
Files:
ingredient-page.html
ingredient-page.js
Requirements:
- Add:
- Add Ingredient: name input + button
- Delete Ingredient: name input + button
- Ingredient list container (ID:
ingredient-list
)
- On page load, call
getIngredients()
- Implement:
addIngredient()
: POST/ingredients
with namedeleteIngredient()
: DELETE/ingredients/{id}
refreshIngredientList()
: Populate list from array- Use:
headers: { "Authorization": "Bearer " + sessionStorage.getItem("auth-token") }
- Token and admin status must be verified via
sessionStorage
CORS (Cross-Origin Resource Sharing) is a security feature implemented by browsers to restrict cross-origin HTTP requests initiated from scripts. Since your frontend and backend run on the same machine but from different contexts (e.g., file://
for frontend vs http://localhost:8081
for backend), CORS preflight requests ensure that the backend explicitly allows the frontend to interact with it.
Modern browsers send a preflight OPTIONS
request before making actual requests like POST
, PUT
, or DELETE
. The backend must respond with the appropriate headers:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Your MockServer and backend are pre-configured to include these headers for all necessary routes.
-
MDN Fetch API Guide:
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch -
MDN CORS Overview:
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS -
JavaScript
fetch()
syntax and examples:
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API