1
0
Fork 0

updated web api docs

This commit is contained in:
Kim, Jimin 2021-09-11 20:20:28 +09:00
parent 2a828df0d7
commit 94f740fe07
2 changed files with 18 additions and 35 deletions

View file

@ -24,19 +24,7 @@ Discord OAuth2 callback
### REST
#### `/users/new`
Create a new user
#### `/users/find`
Find a user
#### `/users`
List all users in the database
#### `/list-servers`
#### `/user-data`
List all servers in the database

View file

@ -20,17 +20,9 @@ This page will teach you how to set up the [Llama bot web API](https://github.co
2. Go to the OAuth2 tab.
3. Add the following redirect URIs:
- localhost for testing
- `http://localhost:5001/<project-id>/us-central1/api`
- `http://localhost:5001/<project-id>/us-central1/api/auth`
- http
- `http://us-central1-<project-id>.cloudfunctions.net/api`
- `http://us-central1-<project-id>.cloudfunctions.net/api/auth`
- https
- `https://us-central1-<project-id>.cloudfunctions.net/api`
- `https://us-central1-<project-id>.cloudfunctions.net/api/auth`
- localhost for testing (http only): `http://localhost:5001/<YOUR_FIREBASE_PROJECT_ID_HERE>/us-central1/api/auth`
- http: `http://us-central1-<YOUR_FIREBASE_PROJECT_ID_HERE>.cloudfunctions.net/api/auth`
- https: `https://us-central1-<YOUR_FIREBASE_PROJECT_ID_HERE>.cloudfunctions.net/api/auth`
### Firebase
@ -41,8 +33,7 @@ This page will teach you how to set up the [Llama bot web API](https://github.co
https://console.firebase.google.com
2. Create/Select a project. Make sure it is using the [blaze plan](https://firebase.google.com/pricing).
3. Go to the `Authentication` tab and enable `Email/Password` Authentication.
4. Go to the `Firestore Database` tab and enable it (using production mode is highly recommended).
3. Go to the `Firestore Database` tab and enable it (using production mode is highly recommended).
### Local
@ -60,12 +51,12 @@ This page will teach you how to set up the [Llama bot web API](https://github.co
git clone git@github.com:llama-bot/llama-bot-web-api.git
```
2. Create `functions/src/config.json` and fill in the data.
2. Edit `functions/src/config.json`.
```json title="functions/src/config.json"
{
"region": "FIREBASE_FUNCTIONS_REGION_HERE", // Region where firebase functions is hosted in. Example: us-central1
"scopes": ["DISCORD", "SCOPES", "HERE"] // Discord OAuth2 scopes. Example: ["identify", "email"]
"scopes": ["DISCORD", "SCOPES", "HERE"] // Discord OAuth2 scopes. Example: ["identify", "email", "guilds"]
}
```
@ -80,19 +71,21 @@ This page will teach you how to set up the [Llama bot web API](https://github.co
}
```
4. Install firebase cli tools.
4. Go to [this link](https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk), select your firebase project and download the firebase admin sdk key by pressing the "Generate new private key" button. Rename it to `firebase-adminsdk.json` and put it in `functions/src/`.
5. Install firebase cli tools.
```bash
npm install -g firebase-tools
```
5. Select firebase project
6. Select firebase project
```bash
firebase use <firebase-project-id>
```
6. Go to `functions` directory and install necessary dependencies.
7. Go to `functions` directory and install necessary dependencies.
```bash
npm install
@ -100,19 +93,21 @@ This page will teach you how to set up the [Llama bot web API](https://github.co
## Testing
1. Start local test server by running the following command:
1. Start local test server by running the following command in the `functions` directory.
```bash
npm run serve
```
2. Open locally served API and log in with your discord account.
:::warning
HTTP**S** won't work when serving locally. Use HTTP instead.
:::
Login test URI: `http://localhost:5001/<FIREBASE-PROJECT-ID>/us-central1/api/login`
Login test URI: `http://localhost:5001/<YOUR_FIREBASE_PROJECT_ID_HERE>/us-central1/api/login`
3. If everything is set up correctly, this should have added a new user that you can check it in the firebase `Authentication` tab.
3. If everything is set up correctly, this should have added a new user in firestore database.
### Deploying
@ -122,7 +117,7 @@ Deploying the functions to production is as simple as running the following comm
firebase deploy
```
Production API URI: `https://us-central1-<firebase-project-id>.cloudfunctions.net/api`.
Production API URL: `https://us-central1-<YOUR_FIREBASE_PROJECT_ID_HERE>.cloudfunctions.net/api`.
## More info