docker的nuxtjs auth Runtime配置
我将NUXT应用程序运行在Docker容器中,目的是构建一次,运行许多。当我运行一个容器时,我想传递nuxt_env_community_id
,每个容器将有所不同。
但是,通过以下设置,当我运行容器时,我会收到一个未定义的错误: nuxt.config.js
auth: {
redirect: {
home: '/home'
},
strategies: {
local: {
endpoints: {
login: {url: "/login", method: "post"},
logout: {url: "/logout", method: "post"},
// user: {url: "/user/" + process.env.NUXT_ENV_COMMUNITY_ID, method: "GET"}
},
token: {
property: 'token',
global: true,
maxAge: 14400,
},
redirectUri: undefined,
}
},
plugins: [{ src: '~/plugins/auth', ssr: true }],
},
env: {
COMMUNITY_ID: process.env.NUXT_ENV_COMMUNITY_ID
},
publicRuntimeConfig: {
communityId: process.env.NUXT_ENV_COMMUNITY_ID
},
privateRuntimeConfig: {
communityId: process.env.NUXT_ENV_COMMUNITY_ID
},
评论输出行生产/user/undefined
auth插件
export default function({ $auth, $config }) {
$auth.strategies.local.options.endpoints.user = {url: "/user/" + $config.communityId, method: "GET"}
}
时,我运行console.log for this。unger.strategies.local.options.endpoints
在nuxtserverinit
中,它打印出来:
login: {
url: '/login',
method: 'post'
},
logout: {
url: '/logout',
method: 'post'
},
user: {
url: '/user/177',
method: 'GET'
}
这是我期望的,但是NUXT试图调用api/auth/user ,而不存在。任何建议都非常感谢!
谢谢!
I run my nuxt app inside a docker container, with the aim of building once, running many. When I run a container, I want to pass in NUXT_ENV_COMMUNITY_ID
which would be different per container.
However, with the following setup, when I run my container, I get an undefined error:
nuxt.config.js
auth: {
redirect: {
home: '/home'
},
strategies: {
local: {
endpoints: {
login: {url: "/login", method: "post"},
logout: {url: "/logout", method: "post"},
// user: {url: "/user/" + process.env.NUXT_ENV_COMMUNITY_ID, method: "GET"}
},
token: {
property: 'token',
global: true,
maxAge: 14400,
},
redirectUri: undefined,
}
},
plugins: [{ src: '~/plugins/auth', ssr: true }],
},
env: {
COMMUNITY_ID: process.env.NUXT_ENV_COMMUNITY_ID
},
publicRuntimeConfig: {
communityId: process.env.NUXT_ENV_COMMUNITY_ID
},
privateRuntimeConfig: {
communityId: process.env.NUXT_ENV_COMMUNITY_ID
},
The commented out line produces /user/undefined
Auth plugin
export default function({ $auth, $config }) {
$auth.strategies.local.options.endpoints.user = {url: "/user/" + $config.communityId, method: "GET"}
}
When I run a console.log for this.$auth.strategies.local.options.endpoints
in nuxtServerInit
, it prints out:
login: {
url: '/login',
method: 'post'
},
logout: {
url: '/logout',
method: 'post'
},
user: {
url: '/user/177',
method: 'GET'
}
Which is what I expect, however Nuxt tries to call api/auth/user
which doesn't exist. Any advice is greatly appreciated!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论