mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
feat(api): validate configuration
This commit is contained in:
parent
ad98ce4e88
commit
e78c6e312d
8 changed files with 109 additions and 12 deletions
|
|
@ -1,5 +1,4 @@
|
|||
import { Module } from "@nestjs/common";
|
||||
import { ConfigModule } from "@nestjs/config";
|
||||
import { ScheduleModule } from "@nestjs/schedule";
|
||||
import { ServeStaticModule } from "@nestjs/serve-static";
|
||||
import { join } from "path";
|
||||
|
|
@ -10,12 +9,14 @@ import { LoggerModule } from "./logger/logger.module";
|
|||
import { MusicLibraryModule } from "./music-library/music-library.module";
|
||||
import { SourcesModule } from "./sources/sources.module";
|
||||
import { UsersModule } from "./users/users.module";
|
||||
import { ConfigModule } from "./config/config.module";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({ isGlobal: true }),
|
||||
ScheduleModule.forRoot(),
|
||||
LoggerModule,
|
||||
ConfigModule,
|
||||
DatabaseModule,
|
||||
ScheduleModule.forRoot(),
|
||||
ServeStaticModule.forRoot({
|
||||
rootPath: join(__dirname, "..", "static"),
|
||||
exclude: ["/api*"],
|
||||
|
|
@ -25,7 +26,6 @@ import { UsersModule } from "./users/users.module";
|
|||
SourcesModule,
|
||||
MusicLibraryModule,
|
||||
ListensModule,
|
||||
LoggerModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ export class SpotifyStrategy extends PassportStrategy(Strategy) {
|
|||
super({
|
||||
clientID: config.get<string>("SPOTIFY_CLIENT_ID"),
|
||||
clientSecret: config.get<string>("SPOTIFY_CLIENT_SECRET"),
|
||||
callbackURL: `${
|
||||
config.get<string>("BASE_DOMAIN") || "http://localhost:3000"
|
||||
}/api/v1/auth/spotify/callback`,
|
||||
callbackURL: `${config.get<string>(
|
||||
"APP_URL"
|
||||
)}/api/v1/auth/spotify/callback`,
|
||||
scope: [
|
||||
"user-read-private",
|
||||
"user-read-email",
|
||||
|
|
|
|||
40
src/config/config.module.ts
Normal file
40
src/config/config.module.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import * as Joi from "@hapi/joi";
|
||||
import { Module } from "@nestjs/common";
|
||||
import {
|
||||
ConfigModule as NestConfigModule,
|
||||
ConfigService,
|
||||
} from "@nestjs/config";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
NestConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
validationSchema: Joi.object({
|
||||
// Application
|
||||
NODE_ENV: Joi.string().valid("dev", "production").default("dev"),
|
||||
PORT: Joi.number().default(3000),
|
||||
APP_URL: Joi.string().default("http://localhost:3000"),
|
||||
|
||||
// JWT
|
||||
JWT_SECRET: Joi.string().required(),
|
||||
JWT_EXPIRATION_TIME: Joi.string().default("1d"),
|
||||
|
||||
// Spotify
|
||||
SPOTIFY_CLIENT_ID: Joi.string().required(),
|
||||
SPOTIFY_CLIENT_SECRET: Joi.string().required(),
|
||||
SPOTIFY_FETCH_INTERVAL_MS: Joi.number().default(5 * 60 * 1000),
|
||||
SPOTIFY_WEB_API_URL: Joi.string().default("https://api.spotify.com/"),
|
||||
SPOTIFY_AUTH_API_URL: Joi.string().default(
|
||||
"https://accounts.spotify.com/"
|
||||
),
|
||||
|
||||
// DB
|
||||
DB_HOST: Joi.string().required(),
|
||||
DB_USERNAME: Joi.string().required(),
|
||||
DB_PASSWORD: Joi.string().required(),
|
||||
DB_DATABASE: Joi.string().required(),
|
||||
}),
|
||||
}),
|
||||
],
|
||||
})
|
||||
export class ConfigModule {}
|
||||
|
|
@ -1,13 +1,15 @@
|
|||
import { HttpModule, Module } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { SpotifyApiService } from "./spotify-api.service";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
HttpModule.registerAsync({
|
||||
useFactory: () => ({
|
||||
useFactory: (config: ConfigService) => ({
|
||||
timeout: 5000,
|
||||
baseURL: "https://api.spotify.com/",
|
||||
baseURL: config.get<string>("SPOTIFY_WEB_API_URL"),
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
],
|
||||
providers: [SpotifyApiService],
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
import { HttpModule, Module } from "@nestjs/common";
|
||||
import { ConfigService } from "@nestjs/config";
|
||||
import { SpotifyAuthService } from "./spotify-auth.service";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
HttpModule.registerAsync({
|
||||
useFactory: () => ({
|
||||
useFactory: (config: ConfigService) => ({
|
||||
timeout: 5000,
|
||||
baseURL: "https://accounts.spotify.com/",
|
||||
baseURL: config.get<string>("SPOTIFY_AUTH_API_URL"),
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
],
|
||||
providers: [SpotifyAuthService],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue