docker的nuxtjs auth Runtime配置

发布于 2025-02-08 23:05:03 字数 1669 浏览 0 评论 0原文

我将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.endpointsnuxtserverinit中,它打印出来:

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文