-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from Vizzuality/feature/api/MARXAN-333-vl-mig…
…rate-from-proxy-controller Feature/api/marxan 333 vl migrate from proxy controller
- Loading branch information
Showing
36 changed files
with
5,337 additions
and
613 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { DocumentBuilder, OpenAPIObject, SwaggerModule } from '@nestjs/swagger'; | ||
|
||
export function addSwagger(app: INestApplication): OpenAPIObject { | ||
const swaggerOptions = new DocumentBuilder() | ||
.setTitle('MarxanCloud API') | ||
.setDescription('MarxanCloud is a conservation planning platform.') | ||
.setVersion(process.env.npm_package_version || 'development') | ||
.addBearerAuth( | ||
{ | ||
type: 'http', | ||
}, | ||
'BearerAuth', | ||
) | ||
.build(); | ||
|
||
return SwaggerModule.createDocument(app, swaggerOptions); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
|
||
import * as helmet from 'helmet'; | ||
import { CorsUtils } from './utils/cors.utils'; | ||
import { AppConfig } from '@marxan-api/utils/config.utils'; | ||
import { ValidationPipe } from '@nestjs/common'; | ||
|
||
export async function bootstrapSetUp() { | ||
const app = await NestFactory.create(AppModule); | ||
|
||
// We forcibly prevent the app from starting if no `API_AUTH_JWT_SECRET` | ||
// environment variable has been set. | ||
if (!AppConfig.get('auth.jwt.secret')) { | ||
throw new Error( | ||
'No secret configured for the signing of JWT tokens. Please set the `API_AUTH_JWT_SECRET` environment variable.', | ||
); | ||
} | ||
|
||
app.use(helmet()); | ||
app.enableCors({ | ||
allowedHeaders: 'Content-Type,Authorization,Content-Disposition', | ||
exposedHeaders: 'Authorization', | ||
origin: CorsUtils.originHandler, | ||
}); | ||
|
||
app.useGlobalPipes( | ||
new ValidationPipe({ | ||
transform: true, | ||
whitelist: true, | ||
forbidNonWhitelisted: true, | ||
}), | ||
); | ||
|
||
return app; | ||
|
||
//await app.listen(3000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { OpenAPIObject } from '@nestjs/swagger'; | ||
import { writeFileSync } from 'fs'; | ||
import { addSwagger } from './add-swagger'; | ||
import { bootstrapSetUp } from './bootstrap-app'; | ||
|
||
export async function generateSwagger() { | ||
const app = await bootstrapSetUp(); | ||
const swaggerDocument = addSwagger(app); | ||
writeFileSync('./swagger.json', JSON.stringify(swaggerDocument)); | ||
} | ||
generateSwagger(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,14 @@ | ||
import { NestFactory } from '@nestjs/core'; | ||
import { AppModule } from './app.module'; | ||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; | ||
import { bootstrapSetUp } from '@marxan-api/bootstrap-app'; | ||
import { addSwagger } from '@marxan-api/add-swagger'; | ||
import { SwaggerModule } from '@nestjs/swagger'; | ||
|
||
import * as helmet from 'helmet'; | ||
import { CorsUtils } from './utils/cors.utils'; | ||
import { AppConfig } from '@marxan-api/utils/config.utils'; | ||
import { ValidationPipe } from '@nestjs/common'; | ||
import { AllExceptionsFilter } from '@marxan-api/filters/all-exceptions.exception.filter'; | ||
export async function bootstrap() { | ||
const app = await bootstrapSetUp(); | ||
const swaggerDocument = addSwagger(app); | ||
|
||
async function bootstrap() { | ||
const app = await NestFactory.create(AppModule); | ||
|
||
// We forcibly prevent the app from starting if no `API_AUTH_JWT_SECRET` | ||
// environment variable has been set. | ||
if (!AppConfig.get('auth.jwt.secret')) { | ||
throw new Error( | ||
'No secret configured for the signing of JWT tokens. Please set the `API_AUTH_JWT_SECRET` environment variable.', | ||
); | ||
} | ||
|
||
app.use(helmet()); | ||
app.enableCors({ | ||
allowedHeaders: 'Content-Type,Authorization,Content-Disposition', | ||
exposedHeaders: 'Authorization', | ||
origin: CorsUtils.originHandler, | ||
}); | ||
|
||
// OpenAPI documentation module - setup | ||
const swaggerOptions = new DocumentBuilder() | ||
.setTitle('MarxanCloud API') | ||
.setDescription('MarxanCloud is a conservation planning platform.') | ||
.setVersion(process.env.npm_package_version || 'development') | ||
.addBearerAuth({ | ||
type: 'apiKey', | ||
in: 'header', | ||
name: 'Authorization', | ||
}) | ||
.build(); | ||
const swaggerDocument = SwaggerModule.createDocument(app, swaggerOptions); | ||
SwaggerModule.setup('/swagger', app, swaggerDocument); | ||
|
||
app.useGlobalPipes( | ||
new ValidationPipe({ | ||
transform: true, | ||
whitelist: true, | ||
forbidNonWhitelisted: true, | ||
}), | ||
); | ||
|
||
await app.listen(3000); | ||
} | ||
|
||
bootstrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.