Using useRequestHeaders inside server / api gives undefined resulting 500 error
See original GitHub issueEnvironment
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:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
import config from '#config'
@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?