hexojs / hexojs/hexo-server

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

Open
#275 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
81
Forks
55
PR merge metrics
No merged PRs in 30d

Description

# 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`

```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": ["/**"]
}
]
}
```

## 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."

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

![image](https://user-images.githubusercontent.com/1673222/220509635-e6317f7a-40f8-4490-85af-384525571035.png)

![image](https://user-images.githubusercontent.com/1673222/220508726-76441905-151e-4487-85d2-0aa18c083c18.png)
![image](https://user-images.githubusercontent.com/1673222/220508829-06d821e7-4aed-473b-b7a1-ee74af0e9611.png)

## 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`.

```zsh
$(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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.