Merge pull request #890 from bluewave-labs/feat/fe/in-app-settings
Feat/fe/in app settings
This commit is contained in:
13 files changed
+531
-17
No files matched your search
@@ -4,7 +4,8 @@ const { updateAppSettingsBodyValidation } = require("../validation/joi");
|
||||
|
||||
const getAppSettings = async (req, res, next) => {
|
||||
try {
|
||||
const settings = await req.settingsService.getSettings();
|
||||
const settings = { ...(await req.settingsService.getSettings()) };
|
||||
delete settings.jwtSecret;
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: successMessages.GET_APP_SETTINGS,
|
||||
@@ -31,7 +32,8 @@ const updateAppSettings = async (req, res, next) => {
|
||||
|
||||
try {
|
||||
await req.db.updateAppSettings(req.body);
|
||||
const updatedSettings = await req.settingsService.reloadSettings();
|
||||
const updatedSettings = { ...(await req.settingsService.reloadSettings()) };
|
||||
delete updatedSettings.jwtSecret;
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
msg: successMessages.UPDATE_APP_SETTINGS,
|
||||
|
||||
@@ -36,7 +36,6 @@ const verifyJWT = (req, res, next) => {
|
||||
const parsedToken = token.slice(TOKEN_PREFIX.length, token.length);
|
||||
// Verify the token's authenticity
|
||||
const { jwtSecret } = req.settingsService.getSettings();
|
||||
|
||||
jwt.verify(parsedToken, jwtSecret, (err, decoded) => {
|
||||
if (err) {
|
||||
return res
|
||||
|
||||
@@ -48,6 +48,7 @@ const AppSettingsSchema = mongoose.Schema(
|
||||
},
|
||||
pagespeedApiKey: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
systemEmailHost: {
|
||||
type: String,
|
||||
|
||||
@@ -2,13 +2,15 @@ const { env } = require("process");
|
||||
const AppSettings = require("../models/AppSettings");
|
||||
const SERVICE_NAME = "SettingsService";
|
||||
const envConfig = {
|
||||
logLevel: undefined,
|
||||
apiBaseUrl: undefined,
|
||||
clientHost: process.env.CLIENT_HOST,
|
||||
jwtSecret: process.env.JWT_SECRET,
|
||||
dbType: process.env.DB_TYPE,
|
||||
dbConnectionString: process.env.DB_CONNECTION_STRING,
|
||||
redisHost: process.env.REDIS_HOST,
|
||||
redisPort: process.env.REDIS_PORT,
|
||||
tokenTTL: process.env.TOKEN_TTL,
|
||||
jwtTTL: process.env.TOKEN_TTL,
|
||||
pagespeedApiKey: process.env.PAGESPEED_API_KEY,
|
||||
systemEmailHost: process.env.SYSTEM_EMAIL_HOST,
|
||||
systemEmailPort: process.env.SYSTEM_EMAIL_PORT,
|
||||
@@ -18,7 +20,7 @@ const envConfig = {
|
||||
|
||||
class SettingsService {
|
||||
constructor() {
|
||||
this.settings = envConfig;
|
||||
this.settings = { ...envConfig };
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
@@ -27,7 +29,6 @@ class SettingsService {
|
||||
if (!this.settings) {
|
||||
throw new Error("Settings not found");
|
||||
}
|
||||
|
||||
// Try to load settings from env first, if not found, load from db
|
||||
for (const key in envConfig) {
|
||||
if (envConfig[key] === undefined && dbSettings[key] !== undefined) {
|
||||
@@ -38,7 +39,6 @@ class SettingsService {
|
||||
if (!this.settings) {
|
||||
throw new Error("Settings not found");
|
||||
}
|
||||
|
||||
return this.settings;
|
||||
} catch (error) {
|
||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||
|
||||
@@ -389,7 +389,6 @@ const updateAppSettingsBodyValidation = joi.object({
|
||||
apiBaseUrl: joi.string().allow(""),
|
||||
logLevel: joi.string().valid("debug", "none", "error", "warn").allow(""),
|
||||
clientHost: joi.string().allow(""),
|
||||
jwtSecret: joi.string().allow(""),
|
||||
dbType: joi.string().allow(""),
|
||||
dbConnectionString: joi.string().allow(""),
|
||||
redisHost: joi.string().allow(""),
|
||||
|
||||
Reference in new issue
Block a user