hexo-server icon indicating copy to clipboard operation
hexo-server copied to clipboard

Debugging in VScode: Websocket error using `127.0.0.1` with node inspector

Open lorezyra opened this issue 3 years ago • 0 comments

Problem

hexo server does not recognize 127.0.0.1 as the same as "localhost."

Environment

  • MacOS 13.2.1

  • node: v19.6.1

  • Hexo:

    • hexo: 6.3.0
    • hexo-cli: 4.2.0
    • os: Darwin 22.3.0 darwin x64
    • node: 19.6.1
    • v8: 10.8.168.25-node.11
    • uv: 1.44.2
    • zlib: 1.2.11
    • brotli: 1.0.9
    • ares: 1.19.0
    • modules: 111
    • nghttp2: 1.52.0
    • napi: 8
    • llhttp: 8.1.0
    • uvwasi: 0.0.15
    • acorn: 8.8.2
    • simdutf: 3.1.0
    • undici: 5.19.1
    • openssl: 1.1.1t
    • cldr: 42.0
    • icu: 72.1
    • tz: 2022e
    • unicode: 15.0

VScode launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-node",
            "name": "Hexo Theme inspector",
            "request": "attach",
            "program": "${workspaceFolder}/node_modules/hexo-cli/bin/hexo",
            "args": [
                "server",
                "-p 4001",
                "--debug"
            ],
            "runtimeExecutable": "node",
            "runtimeArgs": [
                "--inspect-brk=4001"
            ],
            "processId": "${command:PickProcess}",
            "protocol": "inspector",
            "address": "localhost",
            "port": 4001,
            "restart": true,
            "sourceMaps": true,
            "sourceMapPathOverrides": {
                "webpack:///./src/views/*": "${workspaceFolder}/views/*",
                "webpack:///./src/*": "${workspaceFolder}/src/*",
                "webpack:///./../src/*": "${workspaceFolder}/src/*"
            },
            "resolveSourceMapLocations": [
                "${workspaceFolder}/**",
                "!**/node_modules/**"
            ],
            "outFiles": [
                "${workspaceFolder}/**/*.js",
                "${workspaceFolder}/**/*.ejs",
                "${workspaceFolder}/public/**",
                "${workspaceFolder}/themes/**/*.ejs",
                "${workspaceFolder}/themes/**/*.css",
                "${workspaceFolder}/themes/**/*.scss",
                "${workspaceFolder}/themes/**/*.sass",
                "${workspaceFolder}/themes/**/*.less",
                "${workspaceFolder}/themes/**/*.styl",
                "${workspaceFolder}/themes/**/*.png",
                "${workspaceFolder}/themes/**/*.jpg",
                "${workspaceFolder}/themes/**/*.jpeg",
                "${workspaceFolder}/themes/**/*.gif",
                "${workspaceFolder}/themes/**/*.svg",
                "${workspaceFolder}/themes/**/*.woff",
                "${workspaceFolder}/themes/**/*.woff2",
                "${workspaceFolder}/themes/**/*.eot",
                "${workspaceFolder}/themes/**/*.ttf"
            ],
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "${workspaceFolder}",
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "skipFiles": ["<node_internals>/**"]
        }
    ]
}

Debugging with Node

Running the following command in VScode terminal does not properly bind to the default IP address of 127.0.0.1. The server errors with "WebSockets request was expected."

$(which hexo) clean && node --inspect-brk=4001 $(which hexo) server -i localhost -p 4001 --debug

image

image image

Without Node Inspector

I observe if I run Hexo without node inspect, then Hexo will properly bind to both 127.0.0.1 and localhost.

$(which hexo) clean && $(which hexo) server --debug

Expected behavior

Server should accept both "localhost" and "127.0.0.1" on MacOS. Even with Node Inspector, it should respond correctly to IP and "localhost" as the domain.

lorezyra avatar Feb 22 '23 03:02 lorezyra