N
Nuxt2mo ago
dmarr

Debugging server locally with https

I am trying to debug some oauth stuff with my local dev server. The auth service I'm using requires the callback uri to be https, which is annoying. However, I have my dev server running over https using some self-signed certs. The trouble I'm running into is getting the debugger to attach to my local server. I would like to step through some of the server code, but from what I can tell something is amiss from my usual method to do this. I have tried several ways using vscode to no avail. I think the gotcha is that I have to start my server with sudo, since it requires port 443. Any help would be appreciated.
3 Replies
kapa.ai
kapa.ai2mo ago
Hi @dmarr. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To debug your Nuxt server locally with HTTPS, you'll need to make some adjustments to your setup. Here's how you can approach this: 1. First, you can start your Nuxt dev server with HTTPS using the --https flag:
npx nuxi dev --https
npx nuxi dev --https
This will start the dev server with a self-signed certificate as mentioned in the Nuxt documentation (https://nuxt.com/docs/api/commands/dev). 2. If you need to specify your own SSL certificate and key, you can configure it in your nuxt.config.ts file:
export default defineNuxtConfig({
devServer: {
https: {
key: './server.key',
cert: './server.crt'
}
}
})
export default defineNuxtConfig({
devServer: {
https: {
key: './server.key',
cert: './server.crt'
}
}
})
As shown in the Nuxt configuration documentation (https://nuxt.com/docs/api/nuxt-config#devserver). 3. For debugging, you can use the Node inspector. Start your Nuxt dev server with the --inspect flag:
nuxi dev --inspect --https
nuxi dev --inspect --https
This is documented in the Nuxt debugging guide (https://nuxt.com/docs/guide/going-further/debugging#debugging-with-node-inspector). 4. To debug in VS Code, you can use a configuration like this in your launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "server: nuxt",
"outputCapture": "std",
"program": "${workspaceFolder}/node_modules/nuxi/bin/nuxi.mjs",
"args": [
"dev",
"--https"
],
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "server: nuxt",
"outputCapture": "std",
"program": "${workspaceFolder}/node_modules/nuxi/bin/nuxi.mjs",
"args": [
"dev",
"--https"
],
}
]
}
This is adapted from the VS Code debug configuration in the Nuxt documentation (https://nuxt.com/docs/guide/going-further/debugging#debugging-in-your-ide). 5. Regarding the need to use sudo for port 443, it's generally not recommended to run your development server as root. Instead, you could: - Use a higher port number (e.g., 3000) and set up a reverse proxy to forward requests from 443 to your dev server. - Or use a tool like authbind to allow Node.js to bind to port 443 without root privileges. 6. If you're using a self-signed certificate, you might need to set an environment variable to allow Node.js to accept it:
NODE_TLS_REJECT_UNAUTHORIZED=0 nuxi dev --https
NODE_TLS_REJECT_UNAUTHORIZED=0 nuxi dev --https
This is mentioned in the Nuxt documentation for using self-signed certificates (https://nuxt.com/docs/api/utils/dollarfetch). Remember to be cautious when disabling SSL verification, and only do so in a controlled development environment. By following these steps, you should be able to run your Nuxt dev server with HTTPS and debug it effectively. If you're still encountering issues, you might need to provide more specific details about the errors you're seeing. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@139883350096740354> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
dmarr
dmarrOP2mo ago
@kapa.ai for some reason origin is still reporting http even though I am accessing over https: const { origin } = getRequestURL(event);
Want results from more Discord servers?
Add your server