Files
COMERCIAL-GTI/scripts/servidor.mjs
T
Gustavo 4f736562f3 Carry over pre-existing WABA outreach automation WIP
This work already existed uncommitted in the main working tree (not
authored by this branch) and is required as a runtime dependency for the
campaign outreach port (zpro-client, templates, outreach routes/UI). Copied
in as-is, untouched, so this feature branch has a working baseline; the
original uncommitted state in the main checkout is left exactly as it was.
2026-08-01 10:12:25 -03:00

40 lines
1.2 KiB
JavaScript

import { loadDotEnv, GTI_PORT } from '../src/env.mjs';
import { openDb, ensureSeeds } from '../src/db.mjs';
import { createJobManager, recoverOrphans } from '../src/jobs/manager.mjs';
import { createAppServer } from '../src/server/index.mjs';
import { startOutreachScheduler } from '../src/outreach/scheduler.mjs';
// Servidor local do GTI Maquina Comercial. Inicie com:
// npm start (ou node scripts/servidor.mjs, ou o GTI-Comercial.exe)
// e abra http://127.0.0.1:3900 no navegador.
await loadDotEnv();
const log = (message) => console.log(`[servidor] ${message}`);
const db = openDb();
await ensureSeeds(db, { log });
recoverOrphans(db, log);
const jobs = createJobManager();
const server = createAppServer({ db, jobs, log });
startOutreachScheduler({ db, log });
const port = GTI_PORT;
server.listen(port, '127.0.0.1', () => {
log(`GTI Maquina Comercial rodando em http://127.0.0.1:${port}`);
log('somente este computador tem acesso (127.0.0.1). Ctrl+C para encerrar.');
});
function shutdown() {
log('encerrando...');
server.close(() => {
db.close();
process.exit(0);
});
setTimeout(() => process.exit(0), 3000).unref();
}
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);