server-json/readme.md
2025-07-17 23:16:16 +08:00

50 lines
1.3 KiB
Markdown

# Protected REST API with json-server and JWT
This project allows us to use an API Rest to develop in the frontend with mock datas before the backend is finished.
## Install
Clone this repo on your machine and before run `npm i` to install all dependences.
## Start/Stop servers
| Description | Script |
| ------------------------- | -------------------- |
| Start server without auth | `npm start` |
| Start server with auth | `npm run start-auth` |
## Tools
| Description | Script |
| ------------------------------ | ------------------- |
| Generate user hashed passwords | `npm run hash` |
## Endpoints for auth server
| Endpoint | Description |
| ------------------------------ | ------------------- |
| `localhost:4000/auth/login` | Login user |
| `localhost:4000/photos` | Products list (token needed) |
## Change port
in package.json mod -p 4000
[json-server api reference](https://github.com/typicode/json-server)
## How use
- npm run start-auth
- utilizzare index.html per leggere le foto
without auth
- npm start
---
Inspired in this [post](https://www.techiediaries.com/fake-api-jwt-json-server/) by [Techiediaries](https://www.techiediaries.com/)