From 63ba507f026e8ab5981c69bf86fe5aa3101bd91b Mon Sep 17 00:00:00 2001 From: Miguel Puerta Date: Mon, 29 Jul 2024 13:16:43 +0200 Subject: [PATCH] fix: replace boot service with env variable --- .github/workflows/start.yml | 2 +- src/app.js | 4 +--- src/services/boot.service.js | 22 ---------------------- 3 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 src/services/boot.service.js diff --git a/.github/workflows/start.yml b/.github/workflows/start.yml index 52dbc6d..65ed53d 100644 --- a/.github/workflows/start.yml +++ b/.github/workflows/start.yml @@ -16,4 +16,4 @@ jobs: runs-on: [self-hosted, linux, x64, "${{ github.event.inputs.start_env }}"] steps: - name: ${{ github.event.inputs.start_env }} app start - run: PORT=${{ secrets.PORT }} STATUS_SERVER_IP=${{ secrets.STATUS_SERVER_IP }} FF_URL=${{ secrets.FF_URL }} FF_PASWD=${{ secrets.FF_PASWD }} pm2 start npm --name "BLOG" -- start --log-date-format 'DD-MM-YYYY HH:mm:ss' \ No newline at end of file + run: ENV=${{ secrets.ENV }} PORT=${{ secrets.PORT }} STATUS_SERVER_IP=${{ secrets.STATUS_SERVER_IP }} FF_URL=${{ secrets.FF_URL }} FF_PASWD=${{ secrets.FF_PASWD }} pm2 start npm --name "BLOG" -- start --log-date-format 'DD-MM-YYYY HH:mm:ss' \ No newline at end of file diff --git a/src/app.js b/src/app.js index 71e1c94..acabd96 100644 --- a/src/app.js +++ b/src/app.js @@ -8,8 +8,6 @@ const helmet = require('helmet'); const Falconflare = require('@mpuertadev/falconflare-client'); const app = express(); const { assignId, skipStatics, skipStatusServer } = require('./middlewares/morgan'); -const BootService = require('./services/boot.service'); -const execMode = BootService.getExecutionMode(); const PORT = process.env.PORT || 3000; app.use(express.json()) @@ -27,7 +25,7 @@ app.use(async function getLocation(req, res, next) { const ffclient = new Falconflare({serverUrl: process.env.FF_URL, accessKey: process.env.FF_PASSWD}) let ipData; try { - const ip = global.exec_mode == "pro" ? req.headers['x-real-ip'] : req.ip; + const ip = process.env.ENV == "prod" ? req.headers['x-real-ip'] : req.ip; data = await ffclient.getIpData(ip); } catch (error) { console.error('Error fetching IP location:', error); diff --git a/src/services/boot.service.js b/src/services/boot.service.js deleted file mode 100644 index 0d0522f..0000000 --- a/src/services/boot.service.js +++ /dev/null @@ -1,22 +0,0 @@ -const argv = require('yargs').argv; - -global.exec_mode = 'dev'; - -if (argv.mode) { - const modeValue = argv.mode; - const allowedModes = ['dev', 'pro']; - - if (allowedModes.includes(modeValue)) { - global.exec_mode = modeValue; - } else { - console.log('Invalid mode. Allowed modes are: dev, pro, uat. Running in dev mode.'); - } -} - -function getExecutionMode() { - return global.exec_mode; -} - -module.exports = { - getExecutionMode, -}; \ No newline at end of file