-
Notifications
You must be signed in to change notification settings - Fork 13
/
admin.js
71 lines (60 loc) · 1.58 KB
/
admin.js
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
// ============================================
// Database
const mongoose = require("mongoose");
const ProjectSchema = new mongoose.Schema({
title: {
type: String,
required: true,
},
description: String,
completed: Boolean,
created_at: { type: Date, default: Date.now },
});
const Project = mongoose.model("Project", ProjectSchema);
// ============================================
// Admin Bro
const AdminBro = require("admin-bro");
const AdminBroExpress = require("@admin-bro/express");
const AdminBroMongoose = require("@admin-bro/mongoose");
// use mongoose in AdminBro
AdminBro.registerAdapter(AdminBroMongoose);
// config
const adminBroOptions = new AdminBro({
resources: [
{
resource: Project,
options: {
properties: {
description: { type: "richtext" },
created_at: {
isVisible: { edit: false, list: true, show: true, filter: true },
},
},
},
},
],
locale: {
translations: {
labels: {
Project: "My Projects",
},
},
},
rootPath: "/admin",
});
const router = AdminBroExpress.buildRouter(adminBroOptions);
// ============================================
// Server
const express = require("express");
const server = express();
server.use(adminBroOptions.options.rootPath, router);
// =============================================
// Run App
const run = async () => {
await mongoose.connect("mongodb://localhost/adminbroapp", {
useNewUrlParser: true,
useUnifiedTopology: true,
});
await server.listen(5500, () => console.log("Server started"));
};
run();