Skip to content

Commit 758633a

Browse files
author
katt sadecki
committed
🚀 Create working minimal production server - bypasses schema conflicts
1 parent 713c564 commit 758633a

File tree

5 files changed

+90
-3
lines changed

5 files changed

+90
-3
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"dev:server": "NODE_ENV=development tsx watch server/index.ts",
1010
"build": "npm run build:client && npm run build:server",
1111
"build:client": "vite build --mode production",
12-
"build:server": "esbuild server/prod.ts --platform=node --packages=external --bundle --format=esm --outdir=dist --target=node18",
12+
"build:server": "esbuild server/minimal-prod.ts --platform=node --packages=external --bundle --format=esm --outdir=dist --target=node18",
1313
"build:production": "npm run verify-env:production && npm run build && npm run db:push",
14-
"start": "NODE_ENV=production node dist/prod.js",
14+
"start": "NODE_ENV=production node dist/minimal-prod.js",
1515
"start:production": "npm run verify-env:production && NODE_ENV=production node dist/index.js",
1616
"railway:deploy": "npm run build:server && npm run db:push && npm run start",
1717
"preview": "vite preview",

server/db-prod.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'dotenv/config';
2+
import { drizzle } from 'drizzle-orm/neon-http';
3+
import { neon } from '@neondatabase/serverless';
4+
import * as schema from '../shared/pg-schema.js';
5+
6+
if (!process.env.DATABASE_URL) {
7+
throw new Error('DATABASE_URL environment variable is required for production');
8+
}
9+
10+
const sql = neon(process.env.DATABASE_URL);
11+
export const db = drizzle(sql, { schema });
12+
13+
console.log('✅ PostgreSQL database connected successfully');
14+

server/minimal-prod.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import 'dotenv/config';
2+
import express from 'express';
3+
import path from 'path';
4+
import fs from 'fs';
5+
import { createServer } from 'http';
6+
7+
const app = express();
8+
app.use(express.json());
9+
app.use(express.urlencoded({ extended: false }));
10+
11+
// Simple logging middleware
12+
app.use((req, res, next) => {
13+
console.log(`${new Date().toISOString()} ${req.method} ${req.path}`);
14+
next();
15+
});
16+
17+
// Basic API routes that don't depend on complex database operations
18+
app.get('/api/health', (req, res) => {
19+
res.json({ status: 'ok', timestamp: new Date().toISOString() });
20+
});
21+
22+
app.get('/api/test', (req, res) => {
23+
res.json({ message: 'BotSmith API is running!' });
24+
});
25+
26+
// Serve static files from the dist/public directory
27+
const distPath = path.resolve(process.cwd(), 'dist', 'public');
28+
29+
if (!fs.existsSync(distPath)) {
30+
console.error(`Build directory not found: ${distPath}`);
31+
process.exit(1);
32+
}
33+
34+
app.use(express.static(distPath));
35+
36+
// Catch-all handler: serve index.html for any non-API routes
37+
app.use('*', (req, res) => {
38+
res.sendFile(path.resolve(distPath, 'index.html'));
39+
});
40+
41+
// Error handler
42+
app.use((err: any, req: any, res: any, next: any) => {
43+
console.error('Error:', err);
44+
res.status(500).json({ error: 'Internal server error' });
45+
});
46+
47+
const server = createServer(app);
48+
const port = process.env.PORT ? parseInt(process.env.PORT) : 3000;
49+
const host = '0.0.0.0';
50+
51+
server.listen(port, host, () => {
52+
console.log(`🚀 BotSmith server running on ${host}:${port}`);
53+
console.log(`📁 Serving static files from: ${distPath}`);
54+
console.log(`🔗 Visit: http://${host}:${port}`);
55+
});
56+

server/prod.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dotenv/config';
22
import express, { type Request, Response, NextFunction } from "express";
3-
import { registerRoutes } from "./routes";
43
import { log } from "./utils";
54
import path from "path";
65
import fs from "fs";
@@ -40,6 +39,8 @@ app.use((req, res, next) => {
4039
});
4140

4241
(async () => {
42+
// Import routes dynamically to avoid schema conflicts
43+
const { registerRoutes } = await import("./routes.js");
4344
const server = await registerRoutes(app);
4445

4546
app.use((err: any, _req: Request, res: Response, _next: NextFunction) => {

server/routes-prod.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { Express } from "express";
2+
import { createServer, type Server } from "http";
3+
import { WebSocketServer, WebSocket } from "ws";
4+
import { ProductionStorage } from "./storage-prod.js";
5+
6+
// Initialize production storage
7+
const storage = new ProductionStorage();
8+
9+
// In-memory storage for conversation sessions
10+
const conversationSessions = new Map<string, {
11+
currentTemplate: string | null;
12+
agentProfile: Record<string, any>;
13+
agentCreationStage: number;
14+
templates: Record<string, any>;
15+
}>>();
16+

0 commit comments

Comments
 (0)