Need to change websocket baseURL in stubby4j from ws://0.0.0.0:<port>/ws/ to ws://0.0.0.0:<port>/ how to change - stubby4j

Need to change websocket baseURL in stubby4j from ws://0.0.0.0:/ws/ to ws://0.0.0.0:/ how to change

unfortunately the WS URL prefix is not configurable. In other words, it will run on /ws/ only

Related

How to get the full URL for a request in Hapi

In my hapijs app, given a Request object, how can I find the original, unparsed, unmodified URL?
function getRequestUrl (request) {
return ...; // What goes here?
}
I've found that I can piece it together somewhat from Request.info.host, Request.path, and Request.query, but it lacks the scheme (ie, http vs https), and is a bit of a kludge. Isn't the plain URL available somewhere?
The full URL isn't stored somewhere you can get it. You need to build it yourself from the parts:
const url = request.connection.info.protocol
+ '://'
+ request.info.host
+ request.url.path;
Even though it might seem kludgey, it makes sense if you think about it because there is no original, unparsed, unmodified URL. The HTTP request that goes over the wire doesn't contain the URL as typed into the browser address bar for instance:
GET /hello?a=1&b=2 HTTP/1.1 // request.url.path
Host: localhost:4000 // request.info.host
Connection: keep-alive
Accept-Encoding: gzip, deflate, sdch
...
And you only know the protocol based on whether the hapi server connection is in TLS mode or not (request.connection.info.protocol).
Things to be aware of
If you check either:
request.connection.info.uri or request.server.info.uri
the reported hostname will be the hostname of the actual machine that the server is running on (the output of hostname on *nix). If you want the actual host the person typed in the browser (which might be different) you need to check request.info.host which is parsed from the HTTP request's Host header)
Proxies and X-Forwarded-Proto header
If your request got passed through a proxy(ies)/load balancers/HTTPS terminators, it's possible somewhere along the line HTTPS traffic got terminated and was sent to your server on an HTTP connection, in this case you'll want use the value of the x-forwarded-proto header if it's there:
const url = (request.headers['x-forwarded-proto'] || request.connection.info.protocol)
+ '://'
+ request.info.host
+ request.url.path;
With template strings:
const url = `${request.headers['x-forwarded-proto'] || request.connection.info.protocol}://${request.info.host}${request.url.path}`;
hapi-url solves this exact problem. It is prepared to work with X-Forwarded headers to run behind a proxy. There is also an option to override the automatic resolution if the library is not able to resolve the URL correctly.
I use the following syntax now (using coffee script):
server.on 'response', (data) ->
raw = data.raw.req
url = "#{data.connection.info.protocol}://#{raw.headers.host}#{raw.url}"
console.log "Access to #{url}"
Or as javascript:
​server.on('response', function(data) {
var raw = data.raw.req;
var url = data.connection.info.protocol + "://" +
raw.headers.host + raw.url;
console.log("Access to " + url);
});
That gives you the exact URL like the user requested it.
You can't get the URL. You have to generate it. I'm using this one:
const url = request.headers['x-forwarded-proto'] + '://' +
request.headers.host +
request.url.path;
nowadays there is simply request.url:
https://hapi.dev/api?v=20.2.0#-requesturl

Ports in URL - IIS7

I actually need to add a port number to url to access different applications. For example:
http:// moodle.somecollege.com:1000 --> Moodle1 --> C:/Moodle1
http:// moodle.somecollege.com:1001 --> Moodle2 --> C:/Moodle2
http:// moodle.somecollege.com:1002 --> Moodle3 --> C:/Moodle3
This works ok! But now, for some Moodle reason, I need to avoid using the port number to access each site. So, I would need to acces with something like this:
http:// moodle1.moodle.somecollege.com
http:// moodle2.moodle.somecollege.com
http:// moodle3.moodle.somecollege.com
Is there any tool in IIS7 to easily change the "url-with-port" to a url that doesn't require the port. At least explicitly.
Thanks in advance.
--
Angel
Use host headers and change the port to 80. That way you will not need to explicitly provide the URL with Ports.

How to get the correct proxy URL in Apigee?

In my Apigee API Proxy, I need to get the environment URL that is defined in my configuration, so that I can send it as part of the response.
For example: http://myorg-test.apigee.net/pricing
However, when I try to get it using proxy.url, I get an aliased path, like http://rrt18apigee.us-ea.4.apigee.com/pricing
Currently, I'm trying to get it like:
var response = {
proxyUrl : context.getVariable("proxy.url"),
};
Here is a work around. You can try to get the following variables and create the entire URL
Get the request scheme (http or https) from request.Headers.X-Forwarded-Proto (if you are using cloud version) or client.scheme if you are using on-prem
Get the host name from request.host
Get the entire request path from request.path
Entire list of URL query params and list from message.querystring
You can then construct the entire request URL.
( I know this should not be this painful. Please log a bug in case proxy.url is really broken. )

OAuth Redirect URI with Port Forwarding on Unusual Port

I have HTTPS server running on port 4443 and am using port forwarding to send 443 -> 4443 so in the browser you can't tell
In my OAuth settings when I use https://www.domain.com:4443/callback I get the response but in the popup it can't access the parent and I get this Chrome error
Blocked a frame with origin "https://www.domain.com:4443" from accessing a
frame with origin "https://www.domain.com". Protocols, domains, and ports must match.
When I change the url in the OAuth to 443 I get the beloved
`Invalid redirect_uri. This value must match a URL registered with the API Key.`
The only way I can think of is checking via javascript if the port is is the url, and if so to redirect to the url without the port.
Are there any more elegant solutions?
Since nobody has come up with an elegant solution, I thought I'd put my Javascript redirect answer.
What I did was, inside the window that accepts the redirect whose URL will look something like https://www.domain.com:4443/callback?aribtrary_data=1231252...etc... I wrap my callback code inside a try statement. If it fails, I redirect the current page to the same URL minus the port numbers.
Here's my Jade popup window solution which attempts to call the parent window upon finishing.
doctype html
html
head
title Authentication Popup
script.
var service = !{JSON.stringify(service)},
callback = 'on' + service.name + 'Auth';
window.onload = function () {
try {
window.opener[callback](service.error, service);
window.close();
} catch (e) {
window.location = window.location.href.replace(/(\.com)(:\d{3,4})?/, '$1');
}
}
body
| Closing in 1...

How to get the page origin in razor?

I'm looking for the equivalent of this javascript
window.location.origin
but server side, while building mvc pages.
For example, if you are here
http://website.com/123,
it would return
http://website.com
Its important that i have the "http://" part
I'm a fan of
string url = Request.Url.PathAndQuery.length > 1
? Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, string.Empty)
: url;
Keeps your Http/Https, Port (if applicable), and HostName/IP.
DotNetFiddle Examples
Updated to Account for PathAndQuery length of 1.
you could try
#String.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Authority)
Or
#String.Format("{0}://{1}", Request.Url.Scheme, Request.Url.Host)
Authority will include the port number
I think you looking for Request.Url or RawUrl.
Uri.Scheme of Request.Url will give you info on http/https difference.
The window.location.origin in javascript returns the protocol, port (if any), domain and extension of the current url.
If you want to get the same information from an URL, the accepted answers will provide that to you.
If you want the same behavior, ie a piece of javascript is calling your server method and you want to know where it is calling from, you can inspect the HttpRequest.URLReferrer. However this can be spoofed easily and thus is not reliable.

Resources