-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.ts
More file actions
85 lines (69 loc) · 2.54 KB
/
server.ts
File metadata and controls
85 lines (69 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { ObjectKernel } from '@objectstack/core';
import { ObjectQLPlugin } from '@objectstack/objectql';
import { AppPlugin, DriverPlugin } from '@objectstack/runtime';
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
import { InMemoryDriver } from '@objectstack/driver-memory';
import { AuthPlugin } from '@objectstack/plugin-auth';
import config from './objectstack.config';
import { pino } from 'pino';
import { ConsolePlugin } from '../../apps/console/plugin';
async function startServer() {
const logger = pino({
level: 'info',
transport: {
target: 'pino-pretty',
options: {
colorize: true
}
}
});
logger.info('Starting CRM Server...');
try {
// Initialize Kernel
const kernel = new ObjectKernel({
logger,
skipSystemValidation: true
});
// 1. Core Engine (ObjectQL)
const qlPlugin = new ObjectQLPlugin();
await kernel.use(qlPlugin);
// 2. Data Driver (Memory)
const memoryDriver = new InMemoryDriver();
const driverPlugin = new DriverPlugin(memoryDriver);
await kernel.use(driverPlugin);
// 3. Application (crm_app from config)
// The config export from defineStack is treated as an App Bundle or Manifest
const appPlugin = new AppPlugin(config);
await kernel.use(appPlugin);
// 4. Authentication (via @objectstack/plugin-auth)
// NOTE: In production, always set AUTH_SECRET env var. The fallback is for local development only.
const authPlugin = new AuthPlugin({
secret: process.env.AUTH_SECRET || 'objectui-dev-secret',
baseUrl: 'http://localhost:3000',
});
await kernel.use(authPlugin);
// 5. HTTP Server
const serverPlugin = new HonoServerPlugin({ port: 3000 });
await kernel.use(serverPlugin);
// 6. Console Plugin
const consolePlugin = new ConsolePlugin();
await kernel.use(consolePlugin);
// Bootstrap
await kernel.bootstrap();
// Seed Data
try {
// Data is now seeded via manifest in objectstack.config.ts loaded by the app plugin
// or handled by MSW in browser mode.
// We can keep specific server-side seeding here if needed, but for now we rely on the manifest.
logger.info('🌱 checking if data needs seeding...');
} catch (e) {
logger.error(e, 'Failed to seed data');
}
logger.info('✅ CRM Server is running on http://localhost:3000');
logger.info(' GraphQL: http://localhost:3000/graphql');
} catch (error) {
logger.error(error, 'Failed to start server');
process.exit(1);
}
}
startServer();