fix use https back to env var

This commit is contained in:
Simon Larsen
2023-09-29 11:24:45 +00:00
parent 5634b7b586
commit 8a22320532
10 changed files with 22 additions and 121 deletions

View File

@@ -19,7 +19,6 @@ import Users from './Pages/Users/Index';
import Logout from './Pages/Logout/Logout';
// Settings Pages.
import SettingsHost from './Pages/Settings/Host/Index';
import SettingsEmail from './Pages/Settings/SMTP/Index';
import SettingsCallSMS from './Pages/Settings/CallSMS/Index';
import SettingsProbes from './Pages/Settings/Probes/Index';

View File

@@ -1,83 +0,0 @@
import Route from 'Common/Types/API/Route';
import FormFieldSchemaType from 'CommonUI/src/Components/Forms/Types/FormFieldSchemaType';
import CardModelDetail from 'CommonUI/src/Components/ModelDetail/CardModelDetail';
import Page from 'CommonUI/src/Components/Page/Page';
import React, { FunctionComponent, ReactElement } from 'react';
import PageMap from '../../../Utils/PageMap';
import RouteMap, { RouteUtil } from '../../../Utils/RouteMap';
import DashboardSideMenu from '../SideMenu';
import GlobalConfig from 'Model/Models/GlobalConfig';
import ObjectID from 'Common/Types/ObjectID';
import FieldType from 'CommonUI/src/Components/Types/FieldType';
const Settings: FunctionComponent = (): ReactElement => {
return (
<Page
title={'Admin Settings'}
breadcrumbLinks={[
{
title: 'Admin Dashboard',
to: RouteUtil.populateRouteParams(
RouteMap[PageMap.HOME] as Route
),
},
{
title: 'Settings',
to: RouteUtil.populateRouteParams(
RouteMap[PageMap.SETTINGS] as Route
),
},
{
title: 'Host',
to: RouteUtil.populateRouteParams(
RouteMap[PageMap.SETTINGS_HOST] as Route
),
},
]}
sideMenu={<DashboardSideMenu />}
>
{/* Project Settings View */}
<CardModelDetail
name="Host Settings"
cardProps={{
title: 'Host Settings',
description:
'Host Settings for this OneUptime Server instance.',
}}
isEditable={true}
editButtonText="Edit Host"
formFields={[
{
field: {
useHttps: true,
},
title: 'Use HTTPs',
fieldType: FormFieldSchemaType.Toggle,
required: false,
description:
'Is this server hosted with a TLS / SSL cert?',
},
]}
modelDetailProps={{
modelType: GlobalConfig,
id: 'model-detail-global-config',
fields: [
{
field: {
useHttps: true,
},
fieldType: FieldType.Boolean,
title: 'Use HTTPS',
placeholder: 'No',
description:
'Is this server hosted with a valid TLS / SSL cert?',
},
],
modelId: ObjectID.getZeroObjectID(),
}}
/>
</Page>
);
};
export default Settings;

View File

@@ -9,7 +9,7 @@ import {
} from '../Utils/Express';
import Response from '../Utils/Response';
import BaseAPI from './BaseAPI';
import ObjectID from 'Common/Types/ObjectID';
// import ObjectID from 'Common/Types/ObjectID';
export default class GlobalConfigAPI extends BaseAPI<
GlobalConfig,
@@ -26,20 +26,20 @@ export default class GlobalConfigAPI extends BaseAPI<
next: NextFunction
) => {
try {
const globalConfig: GlobalConfig | null =
await GlobalConfigService.findOneById({
id: ObjectID.getZeroObjectID(),
select: {
useHttps: true,
},
props: {
isRoot: true,
},
});
// const globalConfig: GlobalConfig | null =
// await GlobalConfigService.findOneById({
// id: ObjectID.getZeroObjectID(),
// select: {
// useHttps: true,
// },
// props: {
// isRoot: true,
// },
// });
return Response.sendJsonObjectResponse(req, res, {
USE_HTTPS:
globalConfig?.useHttps?.toString() || 'false',
// USE_HTTPS:
// globalConfig?.useHttps?.toString() || 'false',
});
} catch (err) {
next(err);

View File

@@ -37,9 +37,9 @@ export default class DatabaseConfig {
}
public static async getHttpProtocol(): Promise<Protocol> {
return (await DatabaseConfig.getFromGlobalConfig('useHttps'))
return Promise.resolve((process.env['HTTP_PROTOCOL'] === 'https')
? Protocol.HTTPS
: Protocol.HTTP;
: Protocol.HTTP);
}
public static async getAccountsUrl(): Promise<URL> {

View File

@@ -31,7 +31,7 @@ export const env: Function = (key: string): string => {
};
export const HTTP_PROTOCOL: Protocol =
env('USE_HTTPS') === 'true' ? Protocol.HTTPS : Protocol.HTTP;
env('HTTP_PROTOCOL') === 'https' ? Protocol.HTTPS : Protocol.HTTP;
export const HOST: string = env('HOST') || '';

View File

@@ -40,23 +40,6 @@ export enum EmailServerType {
update: [],
})
export default class GlobalConfig extends GlobalConfigModel {
@ColumnAccessControl({
create: [],
read: [],
update: [],
})
@TableColumn({
type: TableColumnType.Boolean,
title: 'Use HTTPS',
description: 'Is this server hosted on with SSL/TLS?',
})
@Column({
type: ColumnType.Boolean,
nullable: true,
unique: true,
default: false,
})
public useHttps?: boolean = undefined;
@ColumnAccessControl({
create: [],

View File

@@ -13,7 +13,6 @@ export default class AddDefaultGlobalConfig extends DataMigrationBase {
const globalConfig: GlobalConfig = new GlobalConfig();
globalConfig.id = ObjectID.getZeroObjectID();
globalConfig.useHttps = false;
globalConfig.emailServerType = EmailServerType.Internal;
globalConfig.sendgridFromName = 'OneUptime';
globalConfig.smtpFromName = 'OneUptime';

View File

@@ -32,9 +32,6 @@ export default class UpdateGlobalConfigFromEnv extends DataMigrationBase {
twilioAuthToken: process.env['TWILIO_AUTH_TOKEN'] || '',
twilioPhoneNumber: process.env['TWILIO_PHONE_NUMBER'] || '',
// Update host
useHttps: process.env['HTTP_PROTOCOL'] === 'https',
// Update SMTP
smtpUsername: process.env['SMTP_USERNAME'] || '',
smtpPassword: process.env['SMTP_PASSWORD'] || '',

View File

@@ -3,6 +3,9 @@
# Please change this to domain of the server where oneuptime is hosted on.
HOST=localhost
# If this server is hosted on SSL / TLS then change this to https
HTTP_PROTOCOL=http
# Secrets - PLEASE CHANGE THESE. Please change these to something random. All of these can be different values.
ONEUPTIME_SECRET=please-change-this-to-random-value
DATABASE_PASSWORD=please-change-this-to-random-value

View File

@@ -2,6 +2,9 @@ version: '3.7'
x-common-variables: &common-variables
HOST: ${HOST}
HTTP_PROTOCOL: ${HTTP_PROTOCOL}
NODE_ENV: ${ENVIRONMENT}
BILLING_ENABLED: ${BILLING_ENABLED}
BILLING_PUBLIC_KEY: ${BILLING_PUBLIC_KEY}