mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 07:04:45 -04:00
Config: Add two new Subconfigs
CustomizationConfig holds all possible customization configs. ExternalConfig holds external services that may be configured. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
c6e341aab9
commit
64846eb641
3 changed files with 135 additions and 0 deletions
|
@ -25,9 +25,13 @@ import hstsConfig from './config/hsts.config';
|
||||||
import cspConfig from './config/csp.config';
|
import cspConfig from './config/csp.config';
|
||||||
import databaseConfig from './config/database.config';
|
import databaseConfig from './config/database.config';
|
||||||
import authConfig from './config/auth.config';
|
import authConfig from './config/auth.config';
|
||||||
|
import customizationConfig from './config/customization.config';
|
||||||
|
import externalConfig from './config/external-services.config';
|
||||||
import { PrivateApiModule } from './api/private/private-api.module';
|
import { PrivateApiModule } from './api/private/private-api.module';
|
||||||
import { ScheduleModule } from '@nestjs/schedule';
|
import { ScheduleModule } from '@nestjs/schedule';
|
||||||
import { RouterModule, Routes } from 'nest-router';
|
import { RouterModule, Routes } from 'nest-router';
|
||||||
|
import { FrontendConfigService } from './frontend-config/frontend-config.service';
|
||||||
|
import { FrontendConfigModule } from './frontend-config/frontend-config.module';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{
|
{
|
||||||
|
@ -53,6 +57,8 @@ const routes: Routes = [
|
||||||
cspConfig,
|
cspConfig,
|
||||||
databaseConfig,
|
databaseConfig,
|
||||||
authConfig,
|
authConfig,
|
||||||
|
customizationConfig,
|
||||||
|
externalConfig,
|
||||||
],
|
],
|
||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
}),
|
}),
|
||||||
|
|
80
src/config/customization.config.ts
Normal file
80
src/config/customization.config.ts
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { registerAs } from '@nestjs/config';
|
||||||
|
import * as Joi from 'joi';
|
||||||
|
import { buildErrorMessage } from './utils';
|
||||||
|
|
||||||
|
export interface CustomizationConfig {
|
||||||
|
branding: {
|
||||||
|
customName: string;
|
||||||
|
customLogo: string;
|
||||||
|
};
|
||||||
|
specialUrls: {
|
||||||
|
privacy: string;
|
||||||
|
termsOfUse: string;
|
||||||
|
imprint: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const schema = Joi.object({
|
||||||
|
branding: Joi.object({
|
||||||
|
customName: Joi.string().optional().label('HD_CUSTOM_NAME'),
|
||||||
|
customLogo: Joi.string()
|
||||||
|
.uri({
|
||||||
|
scheme: [/https?/],
|
||||||
|
})
|
||||||
|
.optional()
|
||||||
|
.label('HD_CUSTOM_LOGO'),
|
||||||
|
}),
|
||||||
|
specialUrls: Joi.object({
|
||||||
|
privacy: Joi.string()
|
||||||
|
.uri({
|
||||||
|
scheme: /https?/,
|
||||||
|
})
|
||||||
|
.optional()
|
||||||
|
.label('HD_PRIVACY_URL'),
|
||||||
|
termsOfUse: Joi.string()
|
||||||
|
.uri({
|
||||||
|
scheme: /https?/,
|
||||||
|
})
|
||||||
|
.optional()
|
||||||
|
.label('HD_TERMS_OF_USE_URL'),
|
||||||
|
imprint: Joi.string()
|
||||||
|
.uri({
|
||||||
|
scheme: /https?/,
|
||||||
|
})
|
||||||
|
.optional()
|
||||||
|
.label('HD_IMPRINT_URL'),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default registerAs('customizationConfig', () => {
|
||||||
|
const customizationConfig = schema.validate(
|
||||||
|
{
|
||||||
|
branding: {
|
||||||
|
customName: process.env.HD_CUSTOM_NAME,
|
||||||
|
customLogo: process.env.HD_CUSTOM_LOGO,
|
||||||
|
},
|
||||||
|
specialUrls: {
|
||||||
|
privacy: process.env.HD_PRIVACY_URL,
|
||||||
|
termsOfUse: process.env.HD_TERMS_OF_USE_URL,
|
||||||
|
imprint: process.env.HD_IMPRINT_URL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
abortEarly: false,
|
||||||
|
presence: 'required',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (customizationConfig.error) {
|
||||||
|
const errorMessages = customizationConfig.error.details.map(
|
||||||
|
(detail) => detail.message,
|
||||||
|
);
|
||||||
|
throw new Error(buildErrorMessage(errorMessages));
|
||||||
|
}
|
||||||
|
return customizationConfig.value as CustomizationConfig;
|
||||||
|
});
|
49
src/config/external-services.config.ts
Normal file
49
src/config/external-services.config.ts
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { registerAs } from '@nestjs/config';
|
||||||
|
import * as Joi from 'joi';
|
||||||
|
import { buildErrorMessage } from './utils';
|
||||||
|
|
||||||
|
export interface ExternalServicesConfig {
|
||||||
|
plantUmlServer: string;
|
||||||
|
imageProxy: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const schema = Joi.object({
|
||||||
|
plantUmlServer: Joi.string()
|
||||||
|
.uri({
|
||||||
|
scheme: /https?/,
|
||||||
|
})
|
||||||
|
.optional()
|
||||||
|
.label('HD_PLANTUML_SERVER'),
|
||||||
|
imageProxy: Joi.string()
|
||||||
|
.uri({
|
||||||
|
scheme: /https?/,
|
||||||
|
})
|
||||||
|
.optional()
|
||||||
|
.label('HD_IMAGE_PROXY'),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default registerAs('externalServicesConfig', () => {
|
||||||
|
const externalConfig = schema.validate(
|
||||||
|
{
|
||||||
|
plantUmlServer: process.env.HD_PLANTUML_SERVER,
|
||||||
|
imageProxy: process.env.HD_IMAGE_PROXY,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
abortEarly: false,
|
||||||
|
presence: 'required',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (externalConfig.error) {
|
||||||
|
const errorMessages = externalConfig.error.details.map(
|
||||||
|
(detail) => detail.message,
|
||||||
|
);
|
||||||
|
throw new Error(buildErrorMessage(errorMessages));
|
||||||
|
}
|
||||||
|
return externalConfig.value as ExternalServicesConfig;
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue