Skip to content

Add hostname route to middleware#308

Merged
giorio94 merged 2 commits into
cilium:masterfrom
giorio94:mio/hostname-route
Apr 27, 2026
Merged

Add hostname route to middleware#308
giorio94 merged 2 commits into
cilium:masterfrom
giorio94:mio/hostname-route

Conversation

@giorio94
Copy link
Copy Markdown
Member

It returns the hostname of the server. For instance:

$ curl --silent localhost:80/hostname

{
  "hostname": "foo"
}

@giorio94 giorio94 requested a review from bimmlerd April 27, 2026 09:16
Comment thread middleware.js

if (req.path.indexOf("/hostname") === 0) {
res.json({ hostname: os.hostname() })
return
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: technically this I guess should not return but also fall through to next

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess either approach should work as we don't expect any further operation afterwards, but omitting the return statement looks indeed more consistent with the other occurrences. Dropping.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spoke too early actually, as omitting the return statement causes the server to emit a log error for every request along the lines of:

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (node:_http_outgoing:642:11)
    at ServerResponse.header (/usr/local/lib/node_modules/json-server/node_modules/express/lib/response.js:794:10)
    at ServerResponse.send (/usr/local/lib/node_modules/json-server/node_modules/express/lib/response.js:174:12)
    at ServerResponse.jsonp (/usr/local/lib/node_modules/json-server/node_modules/express/lib/response.js:351:15)
    at router.render (/usr/local/lib/node_modules/json-server/lib/server/router/index.js:46:9)
    at /usr/local/lib/node_modules/json-server/lib/server/router/index.js:84:12
    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/json-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/usr/local/lib/node_modules/json-server/node_modules/express/lib/router/index.js:328:13)
    at /usr/local/lib/node_modules/json-server/node_modules/express/lib/router/index.js:286:9
    at router.process_params (/usr/local/lib/node_modules/json-server/node_modules/express/lib/router/index.js:346:12)

I'll go ahead and restore the return statement, and add it to the client-ip route as well.

@giorio94 giorio94 force-pushed the mio/hostname-route branch from 88003cb to 7acaa2d Compare April 27, 2026 15:50
It returns the hostname of the server. For instance:

  $ curl --silent localhost:80/hostname

  {
    "hostname": "foo"
  }

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
Otherwise, the downstream logic then tries to set the headers
after that the data has already been sent to the client, causing
log errors along the lines of:

  Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at ServerResponse.setHeader (node:_http_outgoing:642:11)
    at ServerResponse.header (/usr/local/lib/node_modules/json-server/node_modules/express/lib/response.js:794:10)
    at ServerResponse.send (/usr/local/lib/node_modules/json-server/node_modules/express/lib/response.js:174:12)
    at ServerResponse.jsonp (/usr/local/lib/node_modules/json-server/node_modules/express/lib/response.js:351:15)
    at router.render (/usr/local/lib/node_modules/json-server/lib/server/router/index.js:46:9)
    at /usr/local/lib/node_modules/json-server/lib/server/router/index.js:84:12
    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/json-server/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/usr/local/lib/node_modules/json-server/node_modules/express/lib/router/index.js:328:13)
    at /usr/local/lib/node_modules/json-server/node_modules/express/lib/router/index.js:286:9
    at router.process_params (/usr/local/lib/node_modules/json-server/node_modules/express/lib/router/index.js:346:12)

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
@giorio94 giorio94 force-pushed the mio/hostname-route branch from 7acaa2d to 00dec1a Compare April 27, 2026 15:57
@giorio94 giorio94 merged commit 5493310 into cilium:master Apr 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants