-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
78 lines (68 loc) · 1.76 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
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
import express from "express";
import AdminJS, {
AdminJSOptions,
ComponentLoader,
ResourceOptions,
} from "adminjs";
import AdminJSExpress from "@adminjs/express";
import { Database, Resource } from "@adminjs/mongoose";
import mongoose from "mongoose";
import * as dotenv from "dotenv";
import {
CartModel,
CategoryModel,
FavoriteModel,
OrderModel,
ProductModel,
SizeModel,
UserModel,
} from "./sources/mongoose/models";
dotenv.config();
// AdminJS.registerAdapter({Database: MongooseDatabase, Resource: MongooseResource});
const PORT = process.env.PORT || 3000;
// We'll need to register the mongoose Adapter
AdminJS.registerAdapter({
Database,
Resource,
});
const componentLoader = new ComponentLoader();
const Components = {
Dashboard: componentLoader.add("Dashboard", "./components/dashboard"),
};
const start = async (): Promise<void> => {
const app = express();
// This facilitates the connection to the mongo database
await mongoose.connect(`${process.env.MONGO_URI}`);
// We will need to create an instance of AdminJS with a basic resource
const admin = new AdminJS({
resources: [
UserModel,
ProductModel,
CategoryModel,
CartModel,
OrderModel,
FavoriteModel,
SizeModel,
],
branding: {
companyName: "Shoes Shop",
theme: {
colors: { primary100: "#4D70EB" },
},
logo: "",
withMadeWithLove: false,
},
componentLoader: componentLoader,
dashboard: {
component: Components.Dashboard,
},
});
const adminRouter = AdminJSExpress.buildRouter(admin);
app.use(admin.options.rootPath, adminRouter);
app.listen(PORT, () => {
console.log(
`AdminJS started on http://localhost:${PORT}${admin.options.rootPath}`
);
});
};
start();