{"action":"closed","issue":{"url":"https://api.github.com/repos/fbbdev/node-fastcgi/issues/11","repository_url":"https://api.github.com/repos/fbbdev/node-fastcgi","labels_url":"https://api.github.com/repos/fbbdev/node-fastcgi/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/fbbdev/node-fastcgi/issues/11/comments","events_url":"https://api.github.com/repos/fbbdev/node-fastcgi/issues/11/events","html_url":"https://github.com/fbbdev/node-fastcgi/issues/11","id":172305119,"number":11,"title":"Best way to get base URI or baseUrl of executing script?","user":{"login":"binki","id":82626,"avatar_url":"https://avatars.githubusercontent.com/u/82626?v=3","gravatar_id":"","url":"https://api.github.com/users/binki","html_url":"https://github.com/binki","followers_url":"https://api.github.com/users/binki/followers","following_url":"https://api.github.com/users/binki/following{/other_user}","gists_url":"https://api.github.com/users/binki/gists{/gist_id}","starred_url":"https://api.github.com/users/binki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/binki/subscriptions","organizations_url":"https://api.github.com/users/binki/orgs","repos_url":"https://api.github.com/users/binki/repos","events_url":"https://api.github.com/users/binki/events{/privacy}","received_events_url":"https://api.github.com/users/binki/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/fbbdev/node-fastcgi/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/fbbdev/node-fastcgi/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":{"login":"fbbdev","id":3287422,"avatar_url":"https://avatars.githubusercontent.com/u/3287422?v=3","gravatar_id":"","url":"https://api.github.com/users/fbbdev","html_url":"https://github.com/fbbdev","followers_url":"https://api.github.com/users/fbbdev/followers","following_url":"https://api.github.com/users/fbbdev/following{/other_user}","gists_url":"https://api.github.com/users/fbbdev/gists{/gist_id}","starred_url":"https://api.github.com/users/fbbdev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbbdev/subscriptions","organizations_url":"https://api.github.com/users/fbbdev/orgs","repos_url":"https://api.github.com/users/fbbdev/repos","events_url":"https://api.github.com/users/fbbdev/events{/privacy}","received_events_url":"https://api.github.com/users/fbbdev/received_events","type":"User","site_admin":false},"assignees":[{"login":"fbbdev","id":3287422,"avatar_url":"https://avatars.githubusercontent.com/u/3287422?v=3","gravatar_id":"","url":"https://api.github.com/users/fbbdev","html_url":"https://github.com/fbbdev","followers_url":"https://api.github.com/users/fbbdev/followers","following_url":"https://api.github.com/users/fbbdev/following{/other_user}","gists_url":"https://api.github.com/users/fbbdev/gists{/gist_id}","starred_url":"https://api.github.com/users/fbbdev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbbdev/subscriptions","organizations_url":"https://api.github.com/users/fbbdev/orgs","repos_url":"https://api.github.com/users/fbbdev/repos","events_url":"https://api.github.com/users/fbbdev/events{/privacy}","received_events_url":"https://api.github.com/users/fbbdev/received_events","type":"User","site_admin":false}],"milestone":null,"comments":4,"created_at":"2016-08-21T05:05:15Z","updated_at":"2016-08-29T08:12:23Z","closed_at":"2016-08-29T08:12:23Z","body":"I have done some fiddling around and searching through the codebase and I came up with this as a way to discover the URI of the script being executed:\r\n\r\n    let unqualifiedBaseUri = request.cgiParams.SCRIPT_NAME;\r\n\r\nWhat I am really wondering is: is this a supported way to do this sort of thing? Will `cgiParams` always be around? I found `// NOTE: Backward compatibility` next to it in the code. If its deprecated, what is the future API to use for this?\r\n\r\nThe issue with standardization is that this is not really a scenario supported by node’s `http` module. All it does is provide the [raw URI sent by the client](https://nodejs.org/api/http.html#http_message_url). I would like to be able to place my script anywhere and automatically handle its URIs which would match `PATH_INFO` but be capable of generating URIs which relative to the URI that would cause `PATH_INFO` to be `/` or empty. E.g., if my script handles `/asdf` and `/dah` and I access it at `http://example.org/blah/script.cgi/asdf` I want to be able to generate the correct URI for `/dah` which would be `http://example.org/blah/script.cgi/dah`.\r\n\r\nIn ExpressJS, its augmented request object has a [`baseUrl`](https://expressjs.com/en/4x/api.html#req.baseUrl) property. This property is equivalent to `request.cgiParams.SCRIPT_NAME` in node-fastcgi AFAICT. If node-fastcgi extended the request object this same way, you could get something like the following should hopefully be enough to automount an ExpressJS app with zero configuration (this glue could be put in its own npm module…):\r\n\r\n```\r\nvar express = require('express');\r\n\r\n// Set up any express app like normal.\r\nvar app = express();\r\napp.get('/hi', function (request, response) {\r\n  response.send(`hello. Visit bye at: http://${request.hostname}${request.baseUrl}/bye`);\r\n});\r\napp.get('/bye', function (request, response) {\r\n  response.send('bye?');\r\n});\r\n\r\nvar rootApp = express();\r\nvar automount = {};\r\nrequire('node-fastcgi').createServer(function (request) {\r\n  // Compatibility shim\r\n  request.baseUrl = request.baseUrl || request.cgiParams.SCRIPT_NAME;\r\n  if (!automount[request.baseUrl]) {\r\n    rootApp.use(request.baseUrl, app);\r\n    automount[request.baseUrl] = true;\r\n  }\r\n  // ExpressJS gets confused if we set baseUrl because\r\n  // each mount uses its parent’s baseUrl plus its submountpoint\r\n  // as its baseUrl.\r\n  request.baseUrl = undefined;\r\n  return rootApp.apply(this, arguments);\r\n}).listen();\r\n```\r\n\r\nI’d like to get this closer to being just `.createServer(app).listen()` if possible.\r\n\r\nThoughts?"}}
{"actor":{"display_login":"fbbdev"}}