如何在 strapi 中使用根路由 (/) 作为 /admin
How to use the root route (/) as /admin in strapi
我想打开我的子域 admin.example.com 并直接进入管理员登录页面,而不是前面的 index.html 页面告诉我该页面在生产环境中,以提高可用性客户并避免像 admin.example.com/admin.
这样愚蠢的事情
也许我可以用中间件来做,但我一无所知。
我正在使用 heroku。
谢谢
目前不支持。
Currently we don't support serving the admin from the root, added as a feature request
见https://github.com/strapi/strapi/issues/9302
解决方法
您可以使用 custom middleware.
将 /
重定向到 /admin
创建中间件
您可能需要创建目录 (mkdir -p middlewares/redirect/
)。
// middlewares/redirect/index.js
module.exports = () => {
return {
initialize() {
strapi.router.get('/', (ctx) => {
ctx.redirect(strapi.config.get('server.admin.url', '/admin'))
})
},
};
};
启用它
// config/middleware.js
module.exports = {
settings: {
redirect: {
enabled: true
}
}
}
我想打开我的子域 admin.example.com 并直接进入管理员登录页面,而不是前面的 index.html 页面告诉我该页面在生产环境中,以提高可用性客户并避免像 admin.example.com/admin.
这样愚蠢的事情也许我可以用中间件来做,但我一无所知。
我正在使用 heroku。
谢谢
目前不支持。
Currently we don't support serving the admin from the root, added as a feature request
见https://github.com/strapi/strapi/issues/9302
解决方法
您可以使用 custom middleware.
将/
重定向到 /admin
创建中间件
您可能需要创建目录 (mkdir -p middlewares/redirect/
)。
// middlewares/redirect/index.js
module.exports = () => {
return {
initialize() {
strapi.router.get('/', (ctx) => {
ctx.redirect(strapi.config.get('server.admin.url', '/admin'))
})
},
};
};
启用它
// config/middleware.js
module.exports = {
settings: {
redirect: {
enabled: true
}
}
}