- Add streetAddress/city/state/zipCode fields to OfficeContact (schema + storage + UI)
- Support {officeAddress} variable in batch reminder SMS
- Replace single SMS template field with full CRUD template list (add/rename/edit/delete)
- Store SMS template list under _sms_template_list; first template synced to batch reminder
- Hardcode all AI chat template defaults into codebase (reminder SMS, greetings, fallback)
- Add seed-templates.ts that auto-seeds default templates for all users on server boot
- Update README: note that templates are auto-configured on first boot
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
64 lines
1.7 KiB
TypeScript
Executable File
64 lines
1.7 KiB
TypeScript
Executable File
import app from "./app";
|
|
import dotenv from "dotenv";
|
|
import http from "http";
|
|
import { initSocket } from "./socket";
|
|
import { startSeleniumWorker } from "./queue/workers/seleniumWorker";
|
|
import { startOcrWorker } from "./queue/workers/ocrWorker";
|
|
import { seedAllUsersTemplates } from "./storage/seed-templates";
|
|
|
|
dotenv.config();
|
|
|
|
const NODE_ENV = (
|
|
process.env.NODE_ENV ||
|
|
process.env.ENV ||
|
|
"development"
|
|
).toLowerCase();
|
|
const HOST = process.env.HOST || "0.0.0.0";
|
|
const PORT = Number(process.env.PORT) || 5000;
|
|
|
|
// HTTP server from express app
|
|
const server = http.createServer(app);
|
|
|
|
// Initialize socket.io on this server
|
|
initSocket(server);
|
|
|
|
// Start BullMQ workers (requires Redis at localhost:6379)
|
|
startSeleniumWorker();
|
|
startOcrWorker();
|
|
|
|
server.listen(PORT, HOST, () => {
|
|
console.log(
|
|
`✅ Server running in ${NODE_ENV} mode at http://${HOST}:${PORT}`
|
|
);
|
|
seedAllUsersTemplates().catch((err) =>
|
|
console.error("⚠️ Template seed failed:", err)
|
|
);
|
|
});
|
|
|
|
// Handle startup errors
|
|
server.on("error", (err: NodeJS.ErrnoException) => {
|
|
if (err.code === "EADDRINUSE") {
|
|
console.error(`❌ Port ${PORT} is already in use`);
|
|
} else {
|
|
console.error("❌ Server failed to start:", err);
|
|
}
|
|
process.exit(1); // Exit with failure
|
|
});
|
|
|
|
// Graceful shutdown
|
|
const shutdown = (signal: string) => {
|
|
console.log(`⚡ Received ${signal}, shutting down gracefully...`);
|
|
|
|
server.close(() => {
|
|
console.log("✅ HTTP server closed");
|
|
|
|
// TODO: Close DB connections if needed
|
|
// db.$disconnect().then(() => console.log("✅ Database disconnected"));
|
|
|
|
process.exit(0);
|
|
});
|
|
};
|
|
|
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|