Skip to content

Commit

Permalink
Check if module is enabled in server.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
cruizba committed Nov 10, 2024
1 parent 8972411 commit de5aa32
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
5 changes: 5 additions & 0 deletions backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ export const CALL_S3_ACCESS_KEY = process.env.CALL_S3_ACCESS_KEY || undefined;
export const CALL_S3_SECRET_KEY = process.env.CALL_S3_SECRET_KEY || undefined;
export const CALL_AWS_REGION = process.env.CALL_AWS_REGION || undefined;
export const CALL_S3_WITH_PATH_STYLE_ACCESS = process.env.CALL_S3_WITH_PATH_STYLE_ACCESS || 'true';

// Deployment related configuration
export const OPENVIDU_ENVIRONMENT = process.env.OPENVIDU_ENVIRONMENT || undefined;
export const MODULE_NAME = process.env.MODULE_NAME || 'app';
export const ENABLED_MODULES = process.env.ENABLED_MODULES || '';
18 changes: 17 additions & 1 deletion backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import {
CALL_NAME_ID,
SERVER_CORS_ORIGIN,
CALL_S3_PARENT_DIRECTORY,
CALL_S3_RECORDING_DIRECTORY
CALL_S3_RECORDING_DIRECTORY,
OPENVIDU_ENVIRONMENT,
ENABLED_MODULES,
MODULE_NAME,
} from './config.js';

const createApp = () => {
Expand Down Expand Up @@ -138,7 +141,20 @@ const isMainModule = (): boolean => {
return importMetaUrl === processArgv1;
};

const checkModuleIsEnabled = () => {
if (OPENVIDU_ENVIRONMENT) {
const moduleName = MODULE_NAME;
const enabledModules = ENABLED_MODULES.split(',').map((module) => module.trim());

if (!enabledModules.includes(moduleName)) {
console.error(`Module ${moduleName} is not enabled`);
process.exit(0);
}
}
}

if (isMainModule()) {
checkModuleIsEnabled();
const app = createApp();
startServer(app);
}
Expand Down
10 changes: 0 additions & 10 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ if [ -z "${CALL_CONFIG_DIR}" ]; then
fi
fi

# If OPENVIDU_ENVIRONMENT is provided,
# check if the module 'app' is enabled
if [ -n "${OPENVIDU_ENVIRONMENT}" ]; then
if ! echo ",${ENABLED_MODULES:-}," | grep -q ",app,"; then
echo "The module 'app' is not enabled"
exit 0
fi
fi


cd /opt/openvidu-call || { echo "Can't cd into /opt/openvidu-call"; exit 1; }
node dist/src/server.js &

Expand Down

0 comments on commit de5aa32

Please sign in to comment.