Restful API Dropbox - NodeJS v16.x
- Clonar repositorio.
$ git clone <URL>
- Crear
.env
en la raíz y copiar las variables de.env.example
$ cd dbx-api
$ copy .example.env .env
- Instalar dependencias.
$ npm install
- Opcional. Actualizar
src/main.ts
de ser necesario.
const app = await NestFactory.create<NestExpressApplication>(AppModule);
const config = app.get(ConfigService);
const NODE_ENV = config.get<string>("enviroment");
const HOST = config.get<string>("http.host");
const PORT = parseInt(config.get<string>("http.port"), 10)
const corsOptions: CorsOptions = {
origin: '*',
methods: ["GET", "POST", "PATCH", "HEAD", "PUT", "DELETE"]
// credentials: true,
// preflightContinue: false
};
....
}
Si se va a utilizar el endpoint
auth/register
(donde el api se encarga de vincular la cuenta de dropbox)
se tiene que registrar en la aplicación que dropbox el siguiente Redirect URI:{HTTP_PROTOCOL}://hostname:{PORT}/auth/register (omitir puerto en producción)
Ejemplo en local:
http://localhost:5000/auth/register
5. Iniciar.
$ npm build
$ npm run start:prod
Realizar una prueba de conexión rapida.
$ curl.exe -X POST -H "Content-type: application/json" -d '{\"user\":\"test\",\"domain\":\"http:\\example.com\"}' 'https://<hostname>/auth/link_account'
Para que el api se encarge de levantar el form (segundo metodo) se tiene que pasa el
parametro "init" con cualquier valor en el body.
curl -X POST https://<host>/auth/register
--header "Content-Type": "application/x-www-form-urlencoded"
-d \
user: = "test",
domain = "https://example.com/dashboard",
init = true
KEY | Description |
---|---|
APP_HOST |
Host. |
APP_PORT |
Puerto. |
MONGO_URI |
Connection String del host de MongoDB. |
DB_NAME |
Nombre de la base de datos. |
APP_KEY |
El app key de tu dropbox app. |
APP_SECRET |
El app secret de tu dropbox app. |
URL_SWAGGER_APP |
Opcional Host principal para Swagger. |
URL_SWAGGER_SERVER |
Opcional Host secundario para Swagger. |
Account Info
☑ account_info.write
☑ account_info.read
Files and folders
☑ files.metadata.write
☑ files.metadata.read
☑ files.content.write
☑ files.content.read
Collaboration
☑ sharing.read
☑ file_requests.write
☑ file_requests.read
☑ contacts.write
☑ contacts.read
- Crear app en dropbox y obtener las credenciales.
- Registrar Redirect URIs en la sección OAuth2.
- Obtener URI del host de la base de datos de MongoDB.
- Registrar las variables de entorno en el archivo
.env
- Instalar las dependecias.
- Actualizar
main.ts
,app.config.ts
oapp.module.ts
de ser requerido. - Iniciar.