-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
39 lines (30 loc) · 1.35 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
import type { Schema } from './typings';
import 'dotenv/config';
import { CollectionCustomizer, HookBeforeCreateContext, createAgent } from '@forestadmin/agent';
import { createMongooseDataSource } from '@forestadmin/datasource-mongoose';
import connection from './models';
import { customizeCollections, flattenOptions } from './customizations';
// This object allows to configure your Forest Admin panel
const agent = createAgent<Schema>({
// Security tokens
authSecret: process.env.FOREST_AUTH_SECRET!,
envSecret: process.env.FOREST_ENV_SECRET!,
// Make sure to set NODE_ENV to 'production' when you deploy your project
isProduction: process.env.NODE_ENV === 'production',
// Autocompletion of collection names and fields
typingsPath: './typings.ts',
typingsMaxDepth: 5,
});
// Connect your datasources
// All options are documented at https://docs.forestadmin.com/developer-guide-agents-nodejs/data-sources/connection
agent.addDataSource(createMongooseDataSource(connection, { flattenMode: 'manual', flattenOptions }));
customizeCollections(agent);
// Expose an HTTP endpoint.
agent.mountOnStandaloneServer(Number(process.env.APPLICATION_PORT));
// Start the agent.
agent.start().catch(error => {
console.error('\x1b[31merror:\x1b[0m Forest Admin agent failed to start\n');
console.error('');
console.error(error.stack);
process.exit(1);
});