ugh
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 4m30s

This commit is contained in:
2025-12-02 18:43:49 -08:00
parent b800f85f9b
commit 33b1800f72
5 changed files with 50 additions and 25 deletions

View File

@@ -4,16 +4,30 @@
// The .cjs extension is required because the project's package.json has "type": "module".
module.exports = {
apps: [{
name: 'flyer-crawler-api', // The name of our application in PM2
// Explicitly set the working directory. This is crucial for reliability.
cwd: '/var/www/flyer-crawler.projectium.com',
// Use `tsx` directly as the interpreter. PM2 will find it in node_modules/.bin.
// This is more robust than calling `node` on the script path.
apps: [
{
name: 'flyer-crawler-api', // The name of our API application in PM2
// Use tsx as the interpreter and pass the preload script via node_args.
script: './node_modules/.bin/tsx',
args: 'server.ts',
node_args: '-r ./preload.ts',
// Explicitly set the working directory. This is crucial for reliability.
cwd: '/var/www/flyer-crawler.projectium.com',
env_production: {
NODE_ENV: 'production', // Set the Node.js environment to production
},
}],
},
{
name: 'flyer-crawler-worker', // The name of our worker process in PM2
// Use the same preload mechanism for the worker.
script: './node_modules/.bin/tsx',
args: 'src/services/queueService.server.ts',
node_args: '-r ./preload.ts',
// Explicitly set the working directory.
cwd: '/var/www/flyer-crawler.projectium.com',
env_production: {
NODE_ENV: 'production',
},
}
],
};

View File

@@ -14,12 +14,12 @@
"test:integration": "node --max-old-space-size=8192 ./node_modules/vitest/vitest.mjs run --project integration -c vitest.config.integration.ts",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"clean": "rimraf coverage .coverage",
"start:dev": "tsx --env-file .env.test server.ts",
"start:prod": "tsx server.ts",
"start:test": "NODE_V8_COVERAGE=.coverage/tmp/integration-server tsx --env-file .env.test server.ts",
"db:reset:test": "tsx --env-file .env.test src/db/seed.ts",
"worker:dev": "tsx --env-file .env.test src/services/queueService.server.ts",
"worker:prod": "tsx src/services/queueService.server.ts"
"start:dev": "NODE_ENV=development tsx -r ./preload.ts server.ts",
"start:prod": "NODE_ENV=production tsx -r ./preload.ts server.ts",
"start:test": "NODE_ENV=test NODE_V8_COVERAGE=.coverage/tmp/integration-server tsx -r ./preload.ts server.ts",
"db:reset:test": "NODE_ENV=test tsx -r ./preload.ts src/db/seed.ts",
"worker:dev": "NODE_ENV=development tsx -r ./preload.ts src/services/queueService.server.ts",
"worker:prod": "NODE_ENV=production tsx -r ./preload.ts src/services/queueService.server.ts"
},
"dependencies": {
"@bull-board/api": "^6.14.2",

19
preload.ts Normal file
View File

@@ -0,0 +1,19 @@
// preload.ts
/**
* This script is preloaded using Node's --require flag.
* Its purpose is to load the correct environment file (.env or .env.test)
* before any other application code runs. This ensures that `process.env`
* is populated correctly for the given environment (production vs. testing).
*/
import dotenv from 'dotenv';
import path from 'path';
// Determine which .env file to load based on the NODE_ENV variable.
const envFile = process.env.NODE_ENV === 'test' ? '.env.test' : '.env';
const envPath = path.resolve(process.cwd(), envFile);
const result = dotenv.config({ path: envPath });
if (result.error) {
console.error(`[preload.ts] Error loading ${envFile}:`, result.error);
}

View File

@@ -1,9 +1,5 @@
// server.ts
import express, { Request, Response, NextFunction } from 'express';
// Load environment variables from .env file at the very beginning.
import dotenv from 'dotenv';
dotenv.config();
import timeout from 'connect-timeout';
import cookieParser from 'cookie-parser';
import listEndpoints from 'express-list-endpoints';

View File

@@ -1,9 +1,5 @@
// src/services/queueService.server.ts
import { Queue, Worker, Job } from 'bullmq';
// Load environment variables from .env file at the very beginning.
import dotenv from 'dotenv';
dotenv.config();
import IORedis from 'ioredis'; // Correctly imported
import path from 'path';
import fs from 'fs/promises';