fix(plugins): use conditional require for production Docker compatibility
Replace static require('backend/src/...') with NODE_ENV-conditional
requires in compiled plugin JS and TypeScript sources.
In production Docker /app/backend/src/ does not exist — only /app/dist/.
Fixes MODULE_NOT_FOUND errors on UnifiedStorageProvider, ext-api,
leads, nanobana, and uploads plugins.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,16 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createLeadsRoutes = createLeadsRoutes;
|
||||
const express_1 = require("express");
|
||||
const auth_1 = require("../../../backend/src/middleware/auth");
|
||||
const rbac_1 = require("../../../backend/src/middleware/rbac");
|
||||
let authenticate;
|
||||
let authorize;
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
authenticate = require('../../../dist/middleware/auth').authMiddleware;
|
||||
authorize = require('../../../dist/middleware/rbac').adminMiddleware;
|
||||
}
|
||||
else {
|
||||
authenticate = require('../../../backend/src/middleware/auth').authMiddleware;
|
||||
authorize = require('../../../backend/src/middleware/rbac').adminMiddleware;
|
||||
}
|
||||
const STATUS_VALUES = ['new', 'contacted', 'qualified', 'converted', 'lost'];
|
||||
const LEAD_TYPE_VALUES = ['cold', 'member'];
|
||||
function translateLead(lead) {
|
||||
@@ -21,7 +29,7 @@ function translateLead(lead) {
|
||||
function createLeadsRoutes(ctx) {
|
||||
const router = (0, express_1.Router)();
|
||||
const { db } = ctx;
|
||||
const protectedRoutes = [auth_1.authenticate, (0, rbac_1.authorize)(['super_admin', 'admin'])];
|
||||
const protectedRoutes = [authenticate, authorize(['super_admin', 'admin'])];
|
||||
// GET /api/leads/metrics — Global metrics for super admin
|
||||
router.get('/metrics', ...protectedRoutes, async (req, res) => {
|
||||
try {
|
||||
@@ -95,7 +103,7 @@ function createLeadsRoutes(ctx) {
|
||||
res.status(500).json({ error: 'Erro ao buscar métricas' });
|
||||
}
|
||||
});
|
||||
router.get('/', auth_1.authenticate, async (req, res) => {
|
||||
router.get('/', authenticate, async (req, res) => {
|
||||
try {
|
||||
const { partner_id, status, type, page = '1', limit = '20' } = req.query;
|
||||
const offset = (parseInt(page) - 1) * parseInt(limit);
|
||||
@@ -124,7 +132,7 @@ function createLeadsRoutes(ctx) {
|
||||
res.status(500).json({ error: 'Erro ao listar leads' });
|
||||
}
|
||||
});
|
||||
router.get('/:id', auth_1.authenticate, async (req, res) => {
|
||||
router.get('/:id', authenticate, async (req, res) => {
|
||||
try {
|
||||
const id = Number(req.params.id);
|
||||
const lead = await db('leads').where({ id }).first();
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user