-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
51 lines (42 loc) · 1.49 KB
/
index.ts
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
import type { SslMode } from '@forestadmin/datasource-sql';
import 'dotenv/config';
import { createAgent } from '@forestadmin/agent';
import { createSqlDataSource } from '@forestadmin/datasource-sql';
import express from 'express';
import customizations from './customizations';
import type { Schema } from './typings';
import setupApi from './api';
const app = express();
const agent = createAgent<Schema>({
authSecret: process.env.FOREST_AUTH_SECRET!,
envSecret: process.env.FOREST_ENV_SECRET!,
isProduction: process.env.NODE_ENV === 'production',
typingsPath: './typings.ts',
typingsMaxDepth: 5,
});
agent
.addDataSource(
createSqlDataSource({
uri: process.env.DATABASE_URL,
schema: process.env.DATABASE_SCHEMA,
sslMode: process.env.DATABASE_SSL_MODE as SslMode,
}),
)
.addDataSource(customizations.createTypicodeDataSource())
.use(customizations.removeTimestampPlugin, {})
.customizeCollection('users', customizations.users)
.customizeCollection('orders', customizations.orders)
.customizeCollection('order_products', customizations.orderProducts)
.customizeCollection('products', customizations.products);
app.use(setupApi());
agent
.mountOnExpress(app)
.start()
.catch(error => {
// eslint-disable-next-line no-console
console.error('\x1b[31merror:\x1b[0m Forest Admin agent failed to start\n', error.stack);
process.exit(1);
});
app.listen(process.env.PORT, () => {
console.log(`Server is running on port ${process.env.PORT}`);
});