A javascript implementation to deploy JSON Server to Vercel, using Firebase as a simple DataBase storage to allow you to run fake REST API online!
- Login into Firebase Console with your google account.
- Click on "Add project" and follow the prompts to create a new project.
- In the Firebase Console, select your project.
- In the left-hand menu, click on "Build" and then "Realtime Database."
- Click on "Create Database."
- Select your preferred location and set the database to "Start in test mode" (you can change the rules later).
Note: If you want many people to be able to use your databaseat the same time you could configure auth for every user Or for development only, you can set the rules to true.
"rules": { ".read": true, ".write": true }
- Click on the gear icon next to "Project Overview" and select "Project settings."
- Go to the "Service accounts" tab.
- Click on "Generate new private key" and download the JSON file. This file will be used to Authenticate the json-server app with Firebase. Important!: Store the generated file in a config folder in your root app, or save it for later use with environment variables.
- Click on the three dots on the right-hand side of the database toolbar.
- Select "Import JSON."
- Choose your
db.json
file and click "Open" to upload it.
- Clone this repository.
- Run
pnpm install
on the terminal. - Update or use the default
db.json
in the repository. - Sign Up or login into Vercel.
- From the Vercel dashboard, click "+ New Project" then "Import" your repository.
- In the "Configure Project" screen, configure Environment Variables.
-
Under "Environment Variables", add the following variables and fill the values from the generated config file in firebase. See : Set Up Firebase in Your Project
- FIREBASE_PROJECT_ID
- FIREBASE_PRIVATE_KEY
- FIREBASE_CLIENT_EMAIL
-
Leave everything else default and click "Deploy".
-
Save and Wait until deployment is done, and your own JSON server is ready to serve!
Note: If you have already deployed your project to vercel:
- Then Go to your "Vercel project dashboard".
- Navigate to the "Settings" tab.
- Add your "Environment Variables".
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" },
{ "id": 2, "title": "Learning JSON", "author": "student" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 },
{ "id": 2, "body": "another comment", "postId": 1 },
{ "id": 3, "body": "great post!", "postId": 2 }
],
"profile": { "name": "typicode" }
}
filter by category:
/productos?category=comida
filter by 2 categories:
`/productos?category=comida&category=tecnologia`
Usar _expand para relaciones de uno-a-uno (one-to-one relationship).
/requisito-requerimientos?_expand=requerimiento
/requerimientos?_expand=puesto&_expand=empresa
Usar _embed para relaciones de uno-a-varios (one-to-many relationship). Un requerimiento puede tener varios requerimientos asociados
/requerimientos?_embed=requisito-requerimientos
Part of the code in this project was adapted from kitloong's work.