-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
52 lines (47 loc) · 1.48 KB
/
app.ts
File metadata and controls
52 lines (47 loc) · 1.48 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
import AdminJS, { AdminJSOptions } from "adminjs";
import AdminJSExpress from "@adminjs/express";
import express from "express";
import mongoose from "mongoose";
import * as AdminJSMongoose from "@adminjs/mongoose";
import "dotenv/config";
import { MovieResource } from "./movie.resource.js";
import { AdminResource } from "./admin.resource.js";
import { componentLoader } from "./components.js";
import { DashboardOptions } from "./dashboard.config.js";
import { AuthOptions } from "./auth.config.js";
import MongoStore from "connect-mongo";
AdminJS.registerAdapter({
Resource: AdminJSMongoose.Resource,
Database: AdminJSMongoose.Database,
});
const PORT = 3000;
const start = async () => {
const app = express();
await mongoose.connect(process.env.MONGO_DB_URL || "");
const sessionStore = MongoStore.create({
client: mongoose.connection.getClient(),
collectionName: "sessions",
stringify: false,
autoRemove: "interval",
autoRemoveInterval: 1,
});
const adminOptions: AdminJSOptions = {
resources: [MovieResource, AdminResource],
dashboard: DashboardOptions,
componentLoader,
};
const admin = new AdminJS(adminOptions);
const adminRouter = AdminJSExpress.buildAuthenticatedRouter(
admin,
AuthOptions.auth,
null,
AuthOptions.session(sessionStore)
);
app.use(admin.options.rootPath, adminRouter);
app.listen(PORT, () => {
console.log(
`AdminJS started on http://localhost:${PORT}${admin.options.rootPath}`
);
});
};
start();