question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using useRequestHeaders inside server / api gives undefined resulting 500 error

See original GitHub issue

Environment

Nuxt project info:                                                                                                                                  18:34:07

------------------------------
- Operating System: `Linux`
- Node Version:     `v16.14.0`
- Nuxt Version:     `3.0.0-27456065.f38cace`
- Package Manager:  `yarn@1.22.17`
- Builder:          `vite`
- User Config:      `typescript`, `vite`, `build`, `buildModules`, `modules`, `css`, `publicRuntimeConfig`
- Runtime Modules:  `@formkit/nuxt@1.0.0-beta.7-b0764b8`
- Build Modules:    `@nuxtjs/tailwindcss@5.0.1`, `@nuxtjs/google-fonts@1.3.0`, `@pinia/nuxt@0.1.8`
- 

Reproduction

add say auth.ts inside server/api/auth

content of auth.ts

import type { IncomingMessage, ServerResponse } from 'http'

export default async (req: IncomingMessage, res: ServerResponse) => {

const baseUrl = 'http://localhost:81';
  const response: any = await $fetch(
    baseUrl + '/auth/logout',
    {
      method: 'DELETE',
      headers: useRequestHeaders(['cookie'])
    }
  )
 
 res.statusCode = 200
  res.end('Works!')
}

Describe the bug

Now try hitting the endpoint from any page say a function which calls the below It throws

const handler = async () => await $fetch(`/api/auth/hello`)

It will give 500 response and showing the below in terminal

useRequestHeaders is not defined

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
danielroecommented, Mar 16, 2022

import config from '#config'

0reactions
msonowalcommented, Mar 16, 2022

@danielroe ,

thanks for your reply, And I think we should atleast have the ability to use the useRuntimeConfig(). inside the folder is there any way to get that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Web API POST method returns HTTP/1.1 500 Internal Server ...
The Get method is working fine, just getting error in POST. I am using fidler to send post request : Response Header: HTTP/1.1...
Read more >
500 Internal Server Error - Backend Server | Apigee Edge
The HTTP status code 500 is a generic error response. It means that the server encountered an unexpected condition that prevented it from...
Read more >
HTTP 500 Internal Server Error: What It Means & How to Fix It
This code comes from the server when you're trying to access a restricted URL. HTTP 404. A 404 code tells your users that...
Read more >
How to Fix a 500 Internal Server Error on Your WordPress Site
The 500 Internal Server Error status code occurs when the server encounters an error that prevents it from fulfilling the request.
Read more >
500 Internal Server Error - HTTP - MDN Web Docs - Mozilla
Sometimes, server administrators log error responses like the 500 status code with more details about the request to prevent the error from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found