我正在使用 admin bro 为我的项目制作管理面板。
我想要的是更改管理面板的默认 URL。(例如现在 URL 是http://127.0.0.1:3000/admin我想将其更改为http://127.0.0.1:3000/myAdmin)
这是我的代码
const buildAdminRouter = require('./admin/admin.router');
const options = require('./admin/admin.options');
const databaseConnect = async () => {
mongooseDb = await mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex:true })
.then((result) => app.listen(3000))
.catch((err) => console.log(err));
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log("we are connected to database");
});
//-------------Here is Admin Bro Logics---------------------------------------------
const admin = new AdminBro(options)
const router = buildAdminRouter(admin);
app.use(admin.options.rootPath, router);
};
databaseConnect();
选项从这个文件中导入
const {default : AdminBro} = require('admin-bro');
const AdminBroMongoose = require('admin-bro-mongoose');
AdminBro.registerAdapter(AdminBroMongoose);
// const { Company} = require('./Data/company');
const User = require('../models/User');
const Topic = require('../models/topics');
const Question = require('../models/question');
const options = {
// databases : [mongooseDb]
databases : [],
rootpath : '/roshan'
};
module.exports = options;
这是 buildAdminRouter 函数:
const {default : AdminBro} = require('admin-bro');
const {buildRouter} = require('admin-bro-expressjs');
const express = require('express');
const buildAdminRouter = (admin) => {
const router = buildRouter(admin);
return router;
}
module.exports = buildAdminRouter;
编辑1:我在选项中添加了rootpath,但它仍然不起作用,管理面板仍在/admin下。