Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate error about "headers" #1123

Closed
didiself opened this issue Jul 20, 2017 · 5 comments
Closed

generate error about "headers" #1123

didiself opened this issue Jul 20, 2017 · 5 comments
Labels

Comments

@didiself
Copy link

didiself commented Jul 20, 2017

npm run generate
image

my pages
image

list.vue
image

what's wrong and how to fix ???

This bug report is available on Nuxt.js community (#c981)
@atinux
Copy link
Member

atinux commented Jul 20, 2017

This error comes when you try to access req.headers somewhere (maybe in a middleware for your project).

When using nuxt generate, keep in mind that req & res are undefined. See https://nuxtjs.org/api#context

@atinux atinux closed this as completed Jul 20, 2017
@didiself
Copy link
Author

@atinux thanks for your reply.
you are right. But still don't understand.

I write a middleware for get user-agent, and use in layout.

export default function (context) {
  if (context.isServer) {
    let ua = context.req.headers['user-agent']
    context.app.store.state.isWX = !!(/micromessenger/.test(ua.toLowerCase()))
  }
}

I just get some info , didn't change any thing.
How can I improve the code??

@didiself
Copy link
Author

After thinking , I try get userAgent in client.
so generate done without error.

but I think it's should running in server.

@atinux
Copy link
Member

atinux commented Jul 21, 2017

@didiself it cannot run on the server-side since no server is run when nuxt generate & no navigator is used to generate the route.

@lock
Copy link

lock bot commented Nov 3, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 3, 2018
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants