diff --git a/.env.development b/.env.development index fcf8a7e..4f8265c 100755 --- a/.env.development +++ b/.env.development @@ -17,4 +17,8 @@ REACT_APP_API_URL=https://dev1.aptivaai.com/api REACT_APP_ENV=production REACT_APP_OPENAI_API_KEY=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 OPENAI_API_KEY=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 -GCP_CLOUD_SQL_PASSWORD=q2O}1PU-R:|l57S0 \ No newline at end of file +GCP_CLOUD_SQL_PASSWORD=q2O}1PU-R:|l57S0 + +TWILIO_ACCOUNT_SID=ACd700c6fb9f691ccd9ccab73f2dd4173d +TWILIO_AUTH_TOKEN=fb8979ccb172032a249014c9c30eba80 +TWILIO_MESSAGING_SERVICE_SID=MGMGaa07992a9231c841b1bfb879649026d6 \ No newline at end of file diff --git a/Dockerfile.server3 b/Dockerfile.server3 index 13dac0b..0c0f8c3 100644 --- a/Dockerfile.server3 +++ b/Dockerfile.server3 @@ -1,13 +1,18 @@ ARG APPPORT=5002 FROM --platform=$TARGETPLATFORM node:20-slim + WORKDIR /app + COPY package*.json ./ -RUN apt-get update -y && \ - apt-get install -y --no-install-recommends python3 git && \ - rm -rf /var/lib/apt/lists/* -COPY package*.json ./ + +RUN apt-get update -y \ + && apt-get install -y --no-install-recommends python3 git \ + && rm -rf /var/lib/apt/lists/* + RUN npm ci --omit=dev --ignore-scripts + COPY . . + ENV PORT=5002 EXPOSE 5002 -CMD ["node","backend/server3.js"] +CMD ["node", "backend/server3.js"] \ No newline at end of file diff --git a/backend/server3.js b/backend/server3.js index 6e8c503..a2c5b19 100644 --- a/backend/server3.js +++ b/backend/server3.js @@ -1,5 +1,5 @@ // ─── server3.js ──────────────────────────────────────────────────────────── -import './config/env.js'; +import dotenv from 'dotenv'; import path from 'path'; import { fileURLToPath } from 'url'; @@ -23,6 +23,10 @@ import Fuse from 'fuse.js'; import { createReminder } from './utils/smsService.js'; import { cacheSummary } from "./utils/ctxCache.js"; +const rootPath = path.resolve(__dirname, '..'); // one level up +const env = (process.env.NODE_ENV || 'production'); // production in prod +const envPath = path.resolve(rootPath, `.env.${env}`); // => /app/.env.production +dotenv.config({ path: envPath }); const apiBase = process.env.APTIVA_API_BASE || "http://localhost:5002/api"; const app = express(); @@ -52,7 +56,9 @@ app.use(cors({ origin: allowedOrigins, credentials: true })); // 3) Authentication middleware const authenticatePremiumUser = (req, res, next) => { - const token = req.headers.authorization?.split(' ')[1]; + const token = (req.headers.authorization || '') + .replace(/^Bearer\s+/i, '') // drop “Bearer ” + .trim(); // strip CR/LF, spaces if (!token) { return res.status(401).json({ error: 'Premium authorization required' }); } diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 258aff6..378a307 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -34,6 +34,9 @@ services: env_file: [ ./env/prod.env ] environment: - NODE_ENV=production + - TWILIO_ACCOUNT_SID=ACd700c6fb9f691ccd9ccab73f2dd4173d + - TWILIO_AUTH_TOKEN=fb8979ccb172032a249014c9c30eba80 + - TWILIO_MESSAGING_SERVICE_SID=MGMGaa07992a9231c841b1bfb879649026d6 volumes: - /home/jcoakley/aptiva-dev1-app/public:/home/jcoakley/aptiva-dev1-app/public:ro - /home/jcoakley/aptiva-dev1-app/user_profile.db:/home/jcoakley/aptiva-dev1-app/user_profile.db:ro \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8366e99..bedeed4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,6 +23,12 @@ services: image: us-central1-docker.pkg.dev/aptivaai-dev/aptiva-repo/server3:prod-20250710 restart: unless-stopped expose: ["5002"] + environment: + NODE_ENV: production + JWT_SECRET: gW4QsOu4AJA4MooIUC9ld2i71VbBovzV1INsaU6ftxYPrxLIeMq6/OY61j0X2RV7 + TWILIO_ACCOUNT_SID: ACd700c6fb9f691ccd9ccab73f2dd4173d + TWILIO_AUTH_TOKEN: fb8979ccb172032a249014c9c30eba80 + TWILIO_MESSAGING_SERVICE_SID: MGMGaa07992a9231c841b1bfb879649026d6 healthcheck: test: ["CMD-SHELL", "curl -f http://localhost:5002/healthz || exit 1"] interval: 30s