Merge pull request #2227 from bluewave-labs/fix/default-server-port
fix: default server port
This commit is contained in:
17 files changed
+110
-173
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
// Components
|
// Components
|
||||||
import { Box, Stack, Typography, Button, Switch } from "@mui/material";
|
import { Box, Stack, Typography, Button } from "@mui/material";
|
||||||
import TextInput from "../../Components/Inputs/TextInput";
|
import TextInput from "../../Components/Inputs/TextInput";
|
||||||
import Link from "../../Components/Link";
|
import Link from "../../Components/Link";
|
||||||
import Select from "../../Components/Inputs/Select";
|
import Select from "../../Components/Inputs/Select";
|
||||||
@@ -25,12 +25,7 @@ import {
|
|||||||
} from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
} from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
import { update } from "../../Features/Auth/authSlice";
|
import { update } from "../../Features/Auth/authSlice";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import {
|
import { setTimezone, setMode, setLanguage } from "../../Features/UI/uiSlice";
|
||||||
setTimezone,
|
|
||||||
setMode,
|
|
||||||
setDistributedUptimeEnabled,
|
|
||||||
setLanguage,
|
|
||||||
} from "../../Features/UI/uiSlice";
|
|
||||||
import timezones from "../../Utils/timezones.json";
|
import timezones from "../../Utils/timezones.json";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { networkService } from "../../main";
|
import { networkService } from "../../main";
|
||||||
@@ -52,15 +47,18 @@ const Settings = () => {
|
|||||||
const { isLoading: authIsLoading } = useSelector((state) => state.auth);
|
const { isLoading: authIsLoading } = useSelector((state) => state.auth);
|
||||||
const { timezone, distributedUptimeEnabled } = useSelector((state) => state.ui);
|
const { timezone, distributedUptimeEnabled } = useSelector((state) => state.ui);
|
||||||
const { mode } = useSelector((state) => state.ui);
|
const { mode } = useSelector((state) => state.ui);
|
||||||
|
const { pagespeedApiKey } = useSelector((state) => state.settings);
|
||||||
const [checksIsLoading, setChecksIsLoading] = useState(false);
|
const [checksIsLoading, setChecksIsLoading] = useState(false);
|
||||||
const [form, setForm] = useState({
|
const [form, setForm] = useState({
|
||||||
enableDistributedUptime: distributedUptimeEnabled,
|
enableDistributedUptime: distributedUptimeEnabled,
|
||||||
ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0,
|
ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0,
|
||||||
pagespeedApiKey: "",
|
pagespeedApiKey: pagespeedApiKey,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [version, setVersion] = useState("unknown");
|
const [version, setVersion] = useState("unknown");
|
||||||
const [apiKeyFieldType, setApiKeyFieldType] = useState("password");
|
const [apiKeyFieldType, setApiKeyFieldType] = useState("password");
|
||||||
const [isApiKeySet, setIsApiKeySet] = useState(false);
|
const [isApiKeySet, setIsApiKeySet] = useState(pagespeedApiKey ? true : false);
|
||||||
|
const [tempPSKey, setTempPSKey] = useState("");
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
const deleteStatsMonitorsInitState = { deleteMonitors: false, deleteStats: false };
|
const deleteStatsMonitorsInitState = { deleteMonitors: false, deleteStats: false };
|
||||||
const [isOpen, setIsOpen] = useState(deleteStatsMonitorsInitState);
|
const [isOpen, setIsOpen] = useState(deleteStatsMonitorsInitState);
|
||||||
@@ -87,25 +85,7 @@ const Settings = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(getAppSettings());
|
dispatch(getAppSettings());
|
||||||
}, []);
|
}, [dispatch]);
|
||||||
|
|
||||||
const { pagespeedApiKey } = useSelector((state) => state.settings);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (pagespeedApiKey) {
|
|
||||||
setIsApiKeySet(true);
|
|
||||||
setForm((prev) => ({
|
|
||||||
...prev,
|
|
||||||
pagespeedApiKey: t("maskedPageSpeedKeyPlaceholder"),
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
setIsApiKeySet(false);
|
|
||||||
setForm((prev) => ({
|
|
||||||
...prev,
|
|
||||||
pagespeedApiKey: "",
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}, [pagespeedApiKey]);
|
|
||||||
|
|
||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
const { type, checked, value, id } = event.target;
|
const { type, checked, value, id } = event.target;
|
||||||
@@ -118,16 +98,18 @@ const Settings = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (id === "pagespeedApiKey") {
|
||||||
|
setTempPSKey(value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let inputValue = value;
|
let inputValue = value;
|
||||||
if (id === "ttl") {
|
if (id === "ttl") {
|
||||||
inputValue = value.replace(/[^0-9]/g, "");
|
inputValue = value.replace(/[^0-9]/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedForm = { ...form, [id]: inputValue };
|
const updatedForm = { ...form, [id]: inputValue };
|
||||||
const { error } = settingsValidation.validate(
|
const { error } = settingsValidation.validate(updatedForm, { abortEarly: false });
|
||||||
updatedForm,
|
|
||||||
{ abortEarly: false }
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!error || error.details.length === 0) {
|
if (!error || error.details.length === 0) {
|
||||||
setErrors({});
|
setErrors({});
|
||||||
@@ -139,7 +121,7 @@ const Settings = () => {
|
|||||||
setErrors(newErrors);
|
setErrors(newErrors);
|
||||||
logger.error("Validation errors:", error.details);
|
logger.error("Validation errors:", error.details);
|
||||||
}
|
}
|
||||||
|
|
||||||
setForm(updatedForm);
|
setForm(updatedForm);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -153,7 +135,14 @@ const Settings = () => {
|
|||||||
const updatedUser = { ...user, checkTTL: form.ttl };
|
const updatedUser = { ...user, checkTTL: form.ttl };
|
||||||
const [userAction, settingsAction] = await Promise.all([
|
const [userAction, settingsAction] = await Promise.all([
|
||||||
dispatch(update({ localData: updatedUser })),
|
dispatch(update({ localData: updatedUser })),
|
||||||
dispatch(updateAppSettings({ settings: { language: language, pagespeedApiKey: form.pagespeedApiKey } })),
|
dispatch(
|
||||||
|
updateAppSettings({
|
||||||
|
settings: {
|
||||||
|
language: language,
|
||||||
|
pagespeedApiKey: tempPSKey ? tempPSKey : form.pagespeedApiKey,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (userAction.payload.success && settingsAction.payload.success) {
|
if (userAction.payload.success && settingsAction.payload.success) {
|
||||||
@@ -221,7 +210,7 @@ const Settings = () => {
|
|||||||
...prev,
|
...prev,
|
||||||
pagespeedApiKey: "",
|
pagespeedApiKey: "",
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const languages = Object.keys(i18n.options.resources || {});
|
const languages = Object.keys(i18n.options.resources || {});
|
||||||
|
|
||||||
@@ -324,7 +313,7 @@ const Settings = () => {
|
|||||||
<TextInput
|
<TextInput
|
||||||
id="pagespeedApiKey"
|
id="pagespeedApiKey"
|
||||||
label={t("pageSpeedApiKeyFieldLabel")}
|
label={t("pageSpeedApiKeyFieldLabel")}
|
||||||
value={form.pagespeedApiKey}
|
value={form.pagespeedApiKey ? form.pagespeedApiKey : tempPSKey}
|
||||||
type={apiKeyFieldType}
|
type={apiKeyFieldType}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
disabled={isApiKeySet}
|
disabled={isApiKeySet}
|
||||||
@@ -341,12 +330,17 @@ const Settings = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{isApiKeySet && (
|
{isApiKeySet && (
|
||||||
<Box>
|
<Box>
|
||||||
<Typography>{t("pageSpeedApiKeyFieldResetLabel")}</Typography>
|
<Typography>{t("pageSpeedApiKeyFieldResetLabel")}</Typography>
|
||||||
<Button onClick={handleResetApiKey} variant="contained" color="error" sx={{ mt: theme.spacing(4) }}>
|
<Button
|
||||||
{t("reset")}
|
onClick={handleResetApiKey}
|
||||||
</Button>
|
variant="contained"
|
||||||
</Box>
|
color="error"
|
||||||
|
sx={{ mt: theme.spacing(4) }}
|
||||||
|
>
|
||||||
|
{t("reset")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- "80:80"
|
- "80:80"
|
||||||
environment:
|
environment:
|
||||||
UPTIME_APP_API_BASE_URL: "http://localhost:5000/api/v1"
|
UPTIME_APP_API_BASE_URL: "http://localhost:52345/api/v1"
|
||||||
UPTIME_APP_CLIENT_HOST: "http://localhost"
|
UPTIME_APP_CLIENT_HOST: "http://localhost"
|
||||||
volumes:
|
volumes:
|
||||||
- ./nginx/conf.d:/etc/nginx/conf.d/
|
- ./nginx/conf.d:/etc/nginx/conf.d/
|
||||||
@@ -15,7 +15,7 @@ services:
|
|||||||
image: uptime_server:latest
|
image: uptime_server:latest
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "52345:52345"
|
||||||
env_file:
|
env_file:
|
||||||
- server.env
|
- server.env
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# location /api/ {
|
# location /api/ {
|
||||||
# proxy_pass http://server:5000/api/;
|
# proxy_pass http://server:52345/api/;
|
||||||
# proxy_http_version 1.1;
|
# proxy_http_version 1.1;
|
||||||
# proxy_set_header Host $host;
|
# proxy_set_header Host $host;
|
||||||
# proxy_set_header X-Real-IP $remote_addr;
|
# proxy_set_header X-Real-IP $remote_addr;
|
||||||
@@ -24,12 +24,12 @@ server {
|
|||||||
# proxy_cache off;
|
# proxy_cache off;
|
||||||
# }
|
# }
|
||||||
|
|
||||||
location /api-docs/ {
|
# location /api-docs/ {
|
||||||
proxy_pass http://server:5000/api-docs/;
|
# proxy_pass http://server:52345/api-docs/;
|
||||||
proxy_http_version 1.1;
|
# proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
# proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
# proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
# proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
}
|
# }
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,6 @@ RUN npm install
|
|||||||
|
|
||||||
COPY ./server/ ./
|
COPY ./server/ ./
|
||||||
|
|
||||||
EXPOSE 5000
|
EXPOSE 52345
|
||||||
|
|
||||||
CMD ["node", "index.js"]
|
CMD ["node", "index.js"]
|
||||||
Vendored
+1
-1
@@ -8,6 +8,6 @@ RUN npm install
|
|||||||
|
|
||||||
COPY ./server/ ./
|
COPY ./server/ ./
|
||||||
|
|
||||||
EXPOSE 5000
|
EXPOSE 52345
|
||||||
|
|
||||||
CMD ["node", "index.js"]
|
CMD ["node", "index.js"]
|
||||||
@@ -25,7 +25,7 @@ services:
|
|||||||
image: ghcr.io/bluewave-labs/checkmate:backend-demo
|
image: ghcr.io/bluewave-labs/checkmate:backend-demo
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "52345:52345"
|
||||||
env_file:
|
env_file:
|
||||||
- server.env
|
- server.env
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://server:5000/api/;
|
proxy_pass http://server:52345/api/;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
@@ -25,7 +25,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location /api-docs/ {
|
location /api-docs/ {
|
||||||
proxy_pass http://server:5000/api-docs/;
|
proxy_pass http://server:52345/api-docs/;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
@@ -50,7 +50,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://server:5000/api/;
|
proxy_pass http://server:52345/api/;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
@@ -59,7 +59,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location /api-docs/ {
|
location /api-docs/ {
|
||||||
proxy_pass http://server:5000/api-docs/;
|
proxy_pass http://server:52345/api-docs/;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ RUN npm install
|
|||||||
|
|
||||||
COPY ./server ./
|
COPY ./server ./
|
||||||
|
|
||||||
EXPOSE 5000
|
EXPOSE 52345
|
||||||
|
|
||||||
CMD ["node", "index.js"]
|
CMD ["node", "index.js"]
|
||||||
@@ -27,7 +27,7 @@ services:
|
|||||||
image: ghcr.io/bluewave-labs/checkmate:backend-staging
|
image: ghcr.io/bluewave-labs/checkmate:backend-staging
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "5000:5000"
|
- "52345:52345"
|
||||||
env_file:
|
env_file:
|
||||||
- server.env
|
- server.env
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://server:5000/api/;
|
proxy_pass http://server:52345/api/;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
@@ -29,7 +29,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location /api-docs/ {
|
location /api-docs/ {
|
||||||
proxy_pass http://server:5000/api-docs/;
|
proxy_pass http://server:52345/api-docs/;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
@@ -54,7 +54,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://server:5000/api/;
|
proxy_pass http://server:52345/api/;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
@@ -67,7 +67,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
location /api-docs/ {
|
location /api-docs/ {
|
||||||
proxy_pass http://server:5000/api-docs/;
|
proxy_pass http://server:52345/api-docs/;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ RUN npm install
|
|||||||
|
|
||||||
COPY ./server ./
|
COPY ./server ./
|
||||||
|
|
||||||
EXPOSE 5000
|
EXPOSE 52345
|
||||||
|
|
||||||
CMD ["node", "index.js"]
|
CMD ["node", "index.js"]
|
||||||
@@ -11,16 +11,15 @@ class SettingsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAppSettings = async (req, res, next) => {
|
getAppSettings = async (req, res, next) => {
|
||||||
try {
|
const dbSettings = await this.settingsService.getDBSettings();
|
||||||
const settings = { ...(await this.settingsService.getSettings()) };
|
const sanitizedSettings = { ...dbSettings };
|
||||||
delete settings.jwtSecret;
|
if (typeof sanitizedSettings.pagespeedApiKey !== "undefined") {
|
||||||
return res.success({
|
sanitizedSettings.pagespeedApiKey = "********";
|
||||||
msg: this.stringService.getAppSettings,
|
|
||||||
data: settings,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
next(handleError(error, SERVICE_NAME, "getAppSettings"));
|
|
||||||
}
|
}
|
||||||
|
return res.success({
|
||||||
|
msg: this.stringService.getAppSettings,
|
||||||
|
data: sanitizedSettings,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
updateAppSettings = async (req, res, next) => {
|
updateAppSettings = async (req, res, next) => {
|
||||||
|
|||||||
@@ -2,44 +2,9 @@ import mongoose from "mongoose";
|
|||||||
|
|
||||||
const AppSettingsSchema = mongoose.Schema(
|
const AppSettingsSchema = mongoose.Schema(
|
||||||
{
|
{
|
||||||
apiBaseUrl: {
|
language: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
default: "gb",
|
||||||
default: "http://localhost:5000/api/v1",
|
|
||||||
},
|
|
||||||
logLevel: {
|
|
||||||
type: String,
|
|
||||||
default: "debug",
|
|
||||||
enum: ["debug", "none", "error", "warn"],
|
|
||||||
},
|
|
||||||
clientHost: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
default: "http://localhost:5173",
|
|
||||||
},
|
|
||||||
jwtSecret: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
default: "my_secret",
|
|
||||||
},
|
|
||||||
dbType: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
default: "MongoDB",
|
|
||||||
},
|
|
||||||
dbConnectionString: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
default: "mongodb://localhost:27017/uptime_db",
|
|
||||||
},
|
|
||||||
redisUrl: {
|
|
||||||
type: String,
|
|
||||||
default: "redis://127.0.0.1:6379",
|
|
||||||
},
|
|
||||||
jwtTTL: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
default: "2h",
|
|
||||||
},
|
},
|
||||||
pagespeedApiKey: {
|
pagespeedApiKey: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -47,19 +12,15 @@ const AppSettingsSchema = mongoose.Schema(
|
|||||||
},
|
},
|
||||||
systemEmailHost: {
|
systemEmailHost: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "smtp.gmail.com",
|
|
||||||
},
|
},
|
||||||
systemEmailPort: {
|
systemEmailPort: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 465,
|
|
||||||
},
|
},
|
||||||
systemEmailAddress: {
|
systemEmailAddress: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "",
|
|
||||||
},
|
},
|
||||||
systemEmailPassword: {
|
systemEmailPassword: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "",
|
|
||||||
},
|
},
|
||||||
singleton: {
|
singleton: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@@ -73,4 +34,4 @@ const AppSettingsSchema = mongoose.Schema(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export default mongoose.model("AppSettings", AppSettingsSchema);
|
export default mongoose.model("AppSettings", AppSettingsSchema);
|
||||||
@@ -76,7 +76,8 @@ import * as diagnosticModule from "./modules/diagnosticModule.js";
|
|||||||
class MongoDB {
|
class MongoDB {
|
||||||
static SERVICE_NAME = "MongoDB";
|
static SERVICE_NAME = "MongoDB";
|
||||||
|
|
||||||
constructor() {
|
constructor({ appSettings }) {
|
||||||
|
this.appSettings = appSettings;
|
||||||
Object.assign(this, userModule);
|
Object.assign(this, userModule);
|
||||||
Object.assign(this, inviteModule);
|
Object.assign(this, inviteModule);
|
||||||
Object.assign(this, recoveryModule);
|
Object.assign(this, recoveryModule);
|
||||||
@@ -95,8 +96,7 @@ class MongoDB {
|
|||||||
connect = async () => {
|
connect = async () => {
|
||||||
try {
|
try {
|
||||||
const connectionString =
|
const connectionString =
|
||||||
process.env.DB_CONNECTION_STRING || "mongodb://localhost:27017/uptime_db";
|
this.appSettings.dbConnectionString || "mongodb://localhost:27017/uptime_db";
|
||||||
console.log("Connecting to MongoDB with connection string:", connectionString);
|
|
||||||
await mongoose.connect(connectionString);
|
await mongoose.connect(connectionString);
|
||||||
// If there are no AppSettings, create one
|
// If there are no AppSettings, create one
|
||||||
await AppSettings.findOneAndUpdate(
|
await AppSettings.findOneAndUpdate(
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ const getAppSettings = async () => {
|
|||||||
|
|
||||||
const updateAppSettings = async (newSettings) => {
|
const updateAppSettings = async (newSettings) => {
|
||||||
try {
|
try {
|
||||||
|
console.log(newSettings);
|
||||||
const settings = await AppSettings.findOneAndUpdate(
|
const settings = await AppSettings.findOneAndUpdate(
|
||||||
{},
|
{},
|
||||||
{ $set: newSettings },
|
{ $set: newSettings },
|
||||||
{ new: true }
|
{ new: true, upsert: true }
|
||||||
);
|
);
|
||||||
return settings;
|
return settings;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
+12
-11
@@ -100,8 +100,6 @@ const openApiSpec = JSON.parse(
|
|||||||
|
|
||||||
let server;
|
let server;
|
||||||
|
|
||||||
const PORT = 5000;
|
|
||||||
|
|
||||||
const shutdown = async () => {
|
const shutdown = async () => {
|
||||||
if (isShuttingDown) {
|
if (isShuttingDown) {
|
||||||
return;
|
return;
|
||||||
@@ -139,19 +137,21 @@ const shutdown = async () => {
|
|||||||
// Need to wrap server setup in a function to handle async nature of JobQueue
|
// Need to wrap server setup in a function to handle async nature of JobQueue
|
||||||
const startApp = async () => {
|
const startApp = async () => {
|
||||||
const app = express();
|
const app = express();
|
||||||
const allowedOrigin = process.env.CLIENT_HOST;
|
|
||||||
// Create and Register Primary services
|
// Create and Register Primary services
|
||||||
const translationService = new TranslationService(logger);
|
const translationService = new TranslationService(logger);
|
||||||
const stringService = new StringService(translationService);
|
const stringService = new StringService(translationService);
|
||||||
ServiceRegistry.register(StringService.SERVICE_NAME, stringService);
|
ServiceRegistry.register(StringService.SERVICE_NAME, stringService);
|
||||||
|
|
||||||
// Create DB
|
|
||||||
const db = new MongoDB();
|
|
||||||
await db.connect();
|
|
||||||
|
|
||||||
// Create services
|
// Create services
|
||||||
const settingsService = new SettingsService(AppSettings);
|
const settingsService = new SettingsService(AppSettings);
|
||||||
await settingsService.loadSettings();
|
const appSettings = settingsService.loadSettings();
|
||||||
|
|
||||||
|
// Create DB
|
||||||
|
const db = new MongoDB({ appSettings });
|
||||||
|
await db.connect();
|
||||||
|
|
||||||
|
// Set allowed origin
|
||||||
|
const allowedOrigin = appSettings.clientHost;
|
||||||
|
|
||||||
const networkService = new NetworkService(
|
const networkService = new NetworkService(
|
||||||
axios,
|
axios,
|
||||||
@@ -215,8 +215,9 @@ const startApp = async () => {
|
|||||||
|
|
||||||
await translationService.initialize();
|
await translationService.initialize();
|
||||||
|
|
||||||
server = app.listen(PORT, () => {
|
const port = appSettings.port || 52345;
|
||||||
logger.info({ message: `server started on port:${PORT}` });
|
server = app.listen(port, () => {
|
||||||
|
logger.info({ message: `Server started on port:${port}` });
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("SIGUSR2", shutdown);
|
process.on("SIGUSR2", shutdown);
|
||||||
@@ -237,7 +238,7 @@ const startApp = async () => {
|
|||||||
ServiceRegistry.get(SettingsService.SERVICE_NAME),
|
ServiceRegistry.get(SettingsService.SERVICE_NAME),
|
||||||
ServiceRegistry.get(JobQueue.SERVICE_NAME),
|
ServiceRegistry.get(JobQueue.SERVICE_NAME),
|
||||||
ServiceRegistry.get(StringService.SERVICE_NAME),
|
ServiceRegistry.get(StringService.SERVICE_NAME),
|
||||||
ServiceRegistry.get(EmailService.SERVICE_NAME),
|
ServiceRegistry.get(EmailService.SERVICE_NAME)
|
||||||
);
|
);
|
||||||
|
|
||||||
const settingsController = new SettingsController(
|
const settingsController = new SettingsController(
|
||||||
|
|||||||
@@ -1,27 +1,26 @@
|
|||||||
const SERVICE_NAME = "SettingsService";
|
const SERVICE_NAME = "SettingsService";
|
||||||
import dotenv from "dotenv";
|
|
||||||
dotenv.config();
|
|
||||||
const envConfig = {
|
const envConfig = {
|
||||||
|
nodeEnv: process.env.NODE_ENV,
|
||||||
logLevel: process.env.LOG_LEVEL,
|
logLevel: process.env.LOG_LEVEL,
|
||||||
clientHost: process.env.CLIENT_HOST,
|
|
||||||
jwtSecret: process.env.JWT_SECRET,
|
|
||||||
dbType: process.env.DB_TYPE,
|
|
||||||
dbConnectionString: process.env.DB_CONNECTION_STRING,
|
|
||||||
redisUrl: process.env.REDIS_URL,
|
|
||||||
jwtTTL: process.env.TOKEN_TTL,
|
|
||||||
pagespeedApiKey: process.env.PAGESPEED_API_KEY,
|
|
||||||
systemEmailHost: process.env.SYSTEM_EMAIL_HOST,
|
systemEmailHost: process.env.SYSTEM_EMAIL_HOST,
|
||||||
systemEmailPort: process.env.SYSTEM_EMAIL_PORT,
|
systemEmailPort: process.env.SYSTEM_EMAIL_PORT,
|
||||||
systemEmailUser: process.env.SYSTEM_EMAIL_USER,
|
systemEmailUser: process.env.SYSTEM_EMAIL_USER,
|
||||||
systemEmailAddress: process.env.SYSTEM_EMAIL_ADDRESS,
|
systemEmailAddress: process.env.SYSTEM_EMAIL_ADDRESS,
|
||||||
systemEmailPassword: process.env.SYSTEM_EMAIL_PASSWORD,
|
systemEmailPassword: process.env.SYSTEM_EMAIL_PASSWORD,
|
||||||
|
jwtSecret: process.env.JWT_SECRET,
|
||||||
|
jwtTTL: process.env.TOKEN_TTL,
|
||||||
|
clientHost: process.env.CLIENT_HOST,
|
||||||
|
dbConnectionString: process.env.DB_CONNECTION_STRING,
|
||||||
|
redisUrl: process.env.REDIS_URL,
|
||||||
|
callbackUrl: process.env.CALLBACK_URL,
|
||||||
|
port: process.env.PORT,
|
||||||
|
pagespeedApiKey: process.env.PAGESPEED_API_KEY,
|
||||||
|
uprockApiKey: process.env.UPROCK_API_KEY,
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* SettingsService
|
* SettingsService
|
||||||
*
|
*
|
||||||
* This service is responsible for loading and managing the application settings.
|
* This service is responsible for loading and managing the application settings.
|
||||||
* It gives priority to environment variables and will only load settings
|
|
||||||
* from the database if they are not set in the environment.
|
|
||||||
*/
|
*/
|
||||||
class SettingsService {
|
class SettingsService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
@@ -34,40 +33,17 @@ class SettingsService {
|
|||||||
this.settings = { ...envConfig };
|
this.settings = { ...envConfig };
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Load settings from the database and merge with environment settings.
|
* Load settings from env settings
|
||||||
* If there are any settings that weren't set by environment variables, use user settings from the database.
|
* @returns {Object>} The settings.
|
||||||
* @returns {Promise<Object>} The merged settings.
|
*/
|
||||||
* @throws Will throw an error if settings are not found in the database or if settings have not been loaded.
|
loadSettings() {
|
||||||
*/ async loadSettings() {
|
return this.settings;
|
||||||
try {
|
|
||||||
const dbSettings = await this.appSettings.findOne();
|
|
||||||
if (!this.settings) {
|
|
||||||
throw new Error("Settings not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there are any settings that weren't set by environment variables, use user settings from DB
|
|
||||||
for (const key in envConfig) {
|
|
||||||
if (
|
|
||||||
typeof envConfig?.[key] === "undefined" &&
|
|
||||||
typeof dbSettings?.[key] !== "undefined"
|
|
||||||
) {
|
|
||||||
this.settings[key] = dbSettings[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.appSettings.updateOne({}, { $set: this.settings }, { upsert: true });
|
|
||||||
return this.settings;
|
|
||||||
} catch (error) {
|
|
||||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
|
||||||
error.method === undefined ? (error.method = "loadSettings") : null;
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Reload settings by calling loadSettings.
|
* Reload settings by calling loadSettings.
|
||||||
* @returns {Promise<Object>} The reloaded settings.
|
* @returns {Promise<Object>} The reloaded settings.
|
||||||
*/
|
*/
|
||||||
async reloadSettings() {
|
reloadSettings() {
|
||||||
return this.loadSettings();
|
return this.loadSettings();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -81,6 +57,11 @@ class SettingsService {
|
|||||||
}
|
}
|
||||||
return this.settings;
|
return this.settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getDBSettings() {
|
||||||
|
const settings = await this.appSettings.findOne({ singleton: true }).lean();
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default SettingsService;
|
export default SettingsService;
|
||||||
Reference in new issue
Block a user