I have a SignalR-service in two api-versions running in self-hosted Owin processes. I want to route traffic for api.service.com to either api1.service.com or api2.service.com depending on a http-header (api-ver) in a request. Is this possible to do with Owin middleware or in some other way without having to host this in IIS or using a 3rd party reverse proxy or similar? I was hoping it could be done with "Url Rewriting" but I don't know if this is possible in self-hosting?
Have you considered this, I am in the same boat and thinking it will resolve my problem. But to answer your question it does seem possible in self-hosted environments.
Owin.UrlRewrite
EDIT - This library doesn't work (at least I sure can't get it to work). I did experiment with an OWIN middleware of my own and it can be done with redirects but there is a flicker in the URL to essentially the hashtag url (before the client router kicks in (Aurelia in my case) and makes it the non-hash url). Best I can say is this is a limited use case (Self-hosting with need for URL Rewriting) as I cannot find a pre-made solution to do this.
Related
I've searched and searched and can't seem to find a pattern for this. I'd consider myself an intermediate Vue dev, however, the backend is my strong suit. I'm working on an app that will be white-labeled by resellers. While it's possible to have multiple builds, avoiding that would be ideal. The setup is a stand-alone vue-cli SPA connecting to a Laravel api backend and using the Sanctum auth package. So I need calls to the same domain. The issue: resellers will be on their own domain. The ask: Is there a pattern/solution for dynamically loading configs (mainly baseURL) for different domains (other items would by theme/stylesheet). Currently I have a few typical entries:
i.e. axios.defaults.baseURL = process.env.VUE_APP_API_BASE_URL
Basically, based on the domain the site is being served on, I'd like a dynamic/runtime config. I feel like this has been solved, but I can't seem to use the right search terms for some direction, so anything is helpful. I've tried a few things:
1) Parsing in js, but can't seem to get it to run early enough in the process to take effect? It seems to work, but I can't get it to "click"
2) Hit a public API endpoint with the current domain and get the config. Again, can implement, but can't seem to get it to inject into the Vue side correctly?
Any resources, pattern references or general guidance would be much appreciative to avoid maintaining multiple builds merely for a few variables. That said, I don't think there's much overhead in any of this, but also open to telling my I'm wrong and need multiple builds.
End Result
url visited is https://mydomaincom
then baseURL = https://api.mydomiancom
url visited https://resellerdomaincom
then baseURL=https://api.resellerdomaincom
I don't think there is a common pattern to solve your problem - I haven't found anything on the net.
The best software design solution could be the following:
have a single back-end
distribute only the client to your customers/resellers
Obviously the back end could see the domain of the application from which the request comes and manage the logic accordingly.
Good luck with your project.
Honestly how the question is put it's not really clear to me. Although my usual pattern is to:
Create an axios instance like so:
export const axiosInstance = axios.create({
// ...configs
baseURL: process.env.VUE_APP_URL_YOU_WOULD_LIKE_TO_HIT
})
and then whenever I make a request to some api, I would use this instance.
EDIT: According to your edit, you can either release the client to each customer, and have a .env file for each and every of them, or you can have a gateway system, where the client axios end point is always the same, hitting always the same server, and then from there the server decides what to ping, based on your own logic
I am using HAProxy 1.8, I need to make redirection rules, but I do not know the tool well, I have tried but it fails me in some particular cases with different clients.
Client Applications: Adobe Flex 3 (Web) and .Net (Web, WebServices and Desktop).
Necessary redirection example:
Current URL: http://oldsite.com/WS/WSInfo/WSDataClient
URL redirection: http://web1.site.com/WS/WSInfo/WSDataClient
I must perform several redirects (so I have to repeat the rule many times), I can not redirect all "olsite.com" to "web1.site.com", since both balancers will have concurrent calls, not all services, "http://oldsite.com" will stop being used.
The rule of HAProxy:
###----SERV_WSInfo_WSDataClient_test
acl withwsdl_SERV_WSInfo_WSDataClient url /WS/WSInfo/WSDataClient_test?wsdl
acl notwsdl_SERV_WSInfo_WSDataClient path_beg /WS/WSInfo/WSDataClient_test
http-request redirect location http://web1.site.com/WS/WSInfo/WSDataClient?%[query] code 301 if withwsdl_SERV_WSInfo_WSDataClient
http-request redirect location http://web1.site.com/WS/WSInfo/WSDataClient code 301 if notwsdl_SERV_WSInfo_WSDataClient
This works in the Flex applications that consume it, but not in the .Net point, I have been able to detect that:
Flex calls WSDL twice from the service (I suspect that by the redirect of the rule), but it works.
.Net, on the other hand, never asks for the WSDL and the service returns error, blank response.
Someone can recommend how would be the correct way to implement the
rule to achieve the necessary redirection.
To redirect an HTTPS with that same URL, should I add more logic?
They think that I'm not using the necessary tool to do it, they can recommend another one (currently HAProxy is used but if I manage to make it work in another Proxy, I could ask to evaluate).
I thank you for your help since I do not use the tool and I am not from the network area.
Given they are both on different HAProxy servers makes it a bit easier as you dont need to worry about an acl for the new domain. Here is a simple acl that doesnt worry about the querystring at all.
acl is_SERV_TEST url_beg -i /WS/WSInfo/WSDataClient
This acl checks the beginning of the url (case insensitive with the -i) against our url we need to redirec the prefix (host).
http-request redirect code 301 prefix http://web1.site.com if is_SERV_TEST
The redirection simply changes the prefix and maintains the remainder of the URL. For this reason we dont need to worry about the query string etc.
Full Code
acl is_SERV_TEST url_beg -i /WS/WSInfo/WSDataClient
http-request redirect code 301 prefix http://web1.site.com if is_SERV_TEST
SSL Question
For SSL related rewrites this is a double edge sword, and this is against the requirement of the company. For example if you want all request from http://oldsite.com to go to the SSL (HTTPS) url for web1.site.com then you should be doing that in your 301 redirect.
So you would simply change the rewrite prefix to https://web1.site.com.
Finally if you also need to mange the 301 redirect for ssl (ie over port 443) you should create another listener frontend binding to :443 and use the same rules as your port :80 listener.
I need to bypass an MVC route for an application where the developer left - we're going to fully replace it, but for now if I can bypass this one route, it'll save us a ton of time.
The route is (e.g.) www.this.site/path/subpath
Since it's on IIS, I can take advantage of the default document and create the following folder / file structure: /path/subpath/index.htm
However if I do this, I'll "break" the parent www.this.site/path route (it throws a 403 - Forbidden: Access is denied) because I now have an actual file folder where the /path/ route was.
Is there a way to get around this / have IIS defer to MVC on /path/ but still handle the child html file?
thanks. Again, this is not intended as a long term solution but a work-around until we can replace the app entirely.
Perhaps a better workaround would be to use the IIS AAR module and it's reverse proxy functionality out the app.
To do so:
a) stand up the app at it's own site the proper path -- so it should work at something like http://localhost:1234/path/subpath/index.htm
b) install IIS AAR module and enable the reverse proxy functions using the WebPI and the IIS management tools
c) Ignore the /path/subpath route in your app
d) Add a virtual directory for /path/subpath to IIS
e) Configure that to reverse back to localhost:1234 or whatever port you configured the site
This will keep the legacy app completely separate while keeping the public facing URLs looking correct for the rest of the world.
Lets say I have a modular Sinatra app being used for a hundred sites, that I need to conditionally pull in routes for - if the request.host is example.com then I want to register the routes in file example_routes.rb - but if the request.host is say, other_example.com, then I want to register another set of routes completely, ignoring the first file completely.
One could also argue the app is trying to do too many things, but for the sake of this discussion, I'd love to hear some ideas and approaches.
Unfortunately, it appears that by the time the request object comes through (which is needed to register the new routes), that routes can no longer be registered. This is the nature of my problem.
As you’ve noticed, you can’t define routes based on a request since they are all setup at startup before the first request comes in.
One way to achieve what you’re after could be to make use of the :host_name condition:
get 'a_route', :host_name => 'example.com' do
# this route will only apply to requests to example.com
end
get 'a_route', :host_name => 'other_example.com' do
# this route will only apply to requests to other_example.com
end
These can be in different files if you want, and they won’t override each other so you can call them both at startup and requests will be routed to the appropriate code. Development and testing may be tricky, you may need to work out some way of accessing all routes locally.
The setup I have is as follows:
I have one Apache server acting as a URL rewriting engine (SERVER1).
I have a second server (Apache too) which runs a web application (SERVER2). First tries to authenticate users. Part of the authentication protocol involves a lot of redirection between that application server and the authentication server.
My problem is that once the authencation is successfull, the authentication server needs to redirect the user back to the application server, which is only visible from SERVER1. Effectively, SERVER2 needs to be able to reconstruct a URL based on SERVER1's parameters.
Most of the environement variable are helpful i.e. I know the host name, script name, page called etcc but I can 't figure out wether the call was made through HTTP or HTTPS: that information is wiped in the rewrite process by SERVER1...
Anybody knows if/how I can get that information through environement variables? I am limited in that I can't use query string parameters...
Thanks all !
This may sound strange, but I have found part of the answer to my question.
The rewrite engine (at least in Apache 2, I haven't looked anywhere else) allows for writting extra request header.
The rule should look something like that.
RewriteRule .* -
[E=INFO_PATH_INFO:%{PATH_INFO},NE]
Put simple, it creates a new header called INFO_PATH_INFO and sets the value to PATH_INFO.
( For more info check out http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html )
Then it can be retrieved in any languages.
For info I am using Oracle's OWA which adds an extra layer of complication due to the fact that the default environment variables are limited to a few and additional variables need to be specified in thr dads.conf
Hope this will help anyone !