-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
78baf49
commit 6cb7781
Showing
110 changed files
with
1,313 additions
and
654 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
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,2 @@ | ||
keys/jwt.pem | ||
keys/jwt.pem.pub |
Empty file.
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 |
---|---|---|
@@ -1,66 +1,41 @@ | ||
import { getHelmetDirectives, getSwaggerConfig } from '@hikers-book/tsed-swagger'; | ||
import { BaseServer } from '@hikers-book/tsed-common/server'; | ||
import { ConfigServiceBase } from '@hikers-book/tsed-common/services'; | ||
import { getHelmetDirectives, getSwaggerConfig } from '@hikers-book/tsed-common/swagger'; | ||
import '@tsed/ajv'; | ||
import { $log, PlatformApplication } from '@tsed/common'; | ||
import { Configuration, Inject } from '@tsed/di'; | ||
import { Configuration } from '@tsed/di'; | ||
import '@tsed/mongoose'; | ||
import '@tsed/platform-express'; // /!\ keep this import | ||
import bodyParser from 'body-parser'; | ||
import compress from 'compression'; | ||
import cookieParser from 'cookie-parser'; | ||
import cors from 'cors'; | ||
import helmet from 'helmet'; | ||
import methodOverride from 'method-override'; | ||
import { join } from 'path'; | ||
import { config } from './config/index'; | ||
import * as docs from './docs/controllers/pages/index'; | ||
import './providers/ConfigProvider'; | ||
import * as v1 from './v1/controllers/index'; | ||
|
||
@Configuration({ | ||
...config, | ||
acceptMimes: ['application/json'], | ||
disableComponentsScan: true, | ||
// @Configuration decorator from base class is not working | ||
...ConfigServiceBase.getServerDefaults(), | ||
mount: { | ||
'/v1': [...Object.values(v1)], | ||
'/': [...Object.values(docs)] | ||
}, | ||
swagger: getSwaggerConfig(join(__dirname, '../package.json')), | ||
swagger: getSwaggerConfig(), | ||
views: { | ||
root: join(process.cwd(), '../views'), | ||
extensions: { | ||
ejs: 'ejs' | ||
} | ||
}, | ||
exclude: ['**/*.spec.ts'] | ||
} | ||
}) | ||
export class Server { | ||
@Inject() | ||
protected app!: PlatformApplication; | ||
|
||
@Configuration() | ||
protected settings!: Configuration; | ||
|
||
export class Server extends BaseServer { | ||
$beforeRoutesInit(): void { | ||
this.app | ||
.use( | ||
helmet({ | ||
contentSecurityPolicy: { | ||
directives: getHelmetDirectives() | ||
} | ||
}) | ||
) | ||
.use(cors()) | ||
.use(cookieParser()) | ||
.use(compress({})) | ||
.use(methodOverride()) | ||
.use(bodyParser.json()) | ||
.use( | ||
bodyParser.urlencoded({ | ||
extended: true | ||
}) | ||
); | ||
} | ||
this.registerMiddlewares(); | ||
|
||
$onReady(): void { | ||
$log.info(`${this.settings.api} ${this.settings.version} is ready!`); | ||
this.app.use( | ||
helmet({ | ||
contentSecurityPolicy: { | ||
directives: getHelmetDirectives() | ||
} | ||
}) | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
import { Enum, Required } from '@tsed/schema'; | ||
import { Algorithm } from 'jsonwebtoken'; | ||
|
||
export class ConfigJWTModel { | ||
@Required() | ||
@Enum( | ||
'HS256', | ||
'HS384', | ||
'HS512', | ||
'RS256', | ||
'RS384', | ||
'RS512', | ||
'ES256', | ||
'ES384', | ||
'ES512', | ||
'PS256', | ||
'PS384', | ||
'PS512', | ||
'none' | ||
) | ||
algorithm!: Algorithm; | ||
|
||
@Required() | ||
expiresIn!: string; | ||
|
||
@Required() | ||
expiresInRefresh!: string; | ||
} |
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 { MongoDBConfigModel } from '@hikers-book/tsed-common/models'; | ||
import { Required } from '@tsed/schema'; | ||
import { ConfigJWTModel } from './ConfigJWTModel'; | ||
|
||
export class ConfigModel { | ||
@Required() | ||
jwt!: ConfigJWTModel; | ||
|
||
@Required() | ||
mongodb!: MongoDBConfigModel; | ||
} |
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,7 @@ | ||
import { registerProvider } from '@tsed/di'; | ||
import { ConfigService } from '../services/ConfigService'; | ||
|
||
registerProvider({ | ||
provide: ConfigService, | ||
useClass: ConfigService | ||
}); |
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,28 @@ | ||
import { ConfigServiceBase } from '@hikers-book/tsed-common/services'; | ||
import { Injectable } from '@tsed/di'; | ||
import { ConfigModel } from '../models/ConfigModel'; | ||
|
||
@Injectable() | ||
export class ConfigService extends ConfigServiceBase<ConfigModel> { | ||
static api = "Hiker's Book Authentication API"; | ||
static port = 5501; | ||
|
||
constructor() { | ||
super(ConfigService.api, ConfigService.port, ConfigModel); | ||
} | ||
|
||
static getServerConfig(): Partial<TsED.Configuration> { | ||
const config = ConfigServiceBase.load(ConfigService.api, ConfigService.port, ConfigModel); | ||
|
||
return { | ||
...config.base, | ||
mongoose: [ | ||
{ | ||
id: 'authentication', | ||
url: config.file.mongodb.url, | ||
connectionOptions: config.file.mongodb.connectionOptions | ||
} | ||
] | ||
}; | ||
} | ||
} |
Oops, something went wrong.