In Cloud Foundry I have pushed two copies of the same application, Say app1 and app2.
I need to route a specific request from app1 to app2.
Note: app1 and app2 are one and the same, but just i have deployed twice in different name. so the /collections endpoint though it exists in app1, I would like to handle this only via app2 application.So I have created the following routes.
cf map-route app2 mydomain.com --hostname app1 --path collections
cf map-route app1 mydomain.com --hostname app1
By the above route, I expect https://app1.mydomain.com/collections request to handled by app2 application.
Except the /collections endpoint, all the other requests (https://app1.mydomain.com/*) are expected to be handled by app1.
Post the above mentioned router mapping also, I could see that https://app1.mydomain.com/collections request is being served by app1.
But when i have only the below route, expecting all the request to https://app1.mydomain.com/* is to be served by app2. this case is working fine.
cf map-route app2 mydomain.com --hostname app1
So I'm having trouble only routing my https://app1.mydomain.com/collections to a app2 application.
Kindly help me in resolving this.
The behaviour for overlapping routes is not specified in the documentation, so I think the problem that you're having is that your two rules overlap and there is no way to set a precedence that the most specific rule should win.
The solution would be to have mutually exclusive routes.
Related
I followed this tutorial on how to host server side generated sites on Google Cloud Buckets. The issue I am having is that the nuxt app works fine when routing internally, but when I reload a route, the site is redirected to whatever route plus a /index.html at the end.
This causes things to break, as it conflicts with Nuxt routing. I set index to be my entry point ala
gsutil web set -m index.html -e 404.html gs://my-static-assets
but it seems to assume that to be the case always. I don't have this problem using Netlify.
According to the tutorial that you're doing, you're redirected to /route/index.html because of your MainPageSuffix index, this means that when you try to access for example https://example.com/route the service look for the target https:// example.com/route/index.html.
To fix this I suggest that you include an index.html file under the subdirectory in the subdirectory of the route.
I recommend, for further info on this to check this post which has a similar issue.
We run multiple applications in Cloudfoundry.
Now we have the requirement to distinguish app requests by path - this is clearly possible by using
cf create-route myspace mydomain.com –hostname myapp –path foo
cf map-route my-app mydomain.com –hostname myapp –path foo
cf create-route myspace mydomain.com –hostname myapp –path bar
cf map-route my-another-app mydomain.com –hostname myapp –path bar
now the requests are routed like this:
http://myapp.mydomain.com/foo -> my-app
http://myapp.mydomain.com/bar -> my-another-app
but to make this all work, I also need a DNS entry to resolve myapp.mydomain.com, to where do I point the CNAME record e.g. on cloudflare for myapp.mydomain.com?
my-app.scapp.io or my-another-app.scapp.io do not look correct, because its not one or the other I want to address, but both.
Typically you'd make a CNAME record that points to the default route assigned to your app. It looks like my-app.scapp.io in your example above, but you can run cf app <name> and find the assigned route.
Because you're using path-based routing, you'd only need one CNAME record for both apps. It would then be up to the client to select the correct path such that they are routed to the right application.
Let's assume I own the domain:
foobar.com/
I want to use Netlify for my static pages like
foobar.com/features/
foobar.com/pricing/
foobar.com/imprint/
etc.
But I also have a Django application on a seperate server on AWS that has nothing to do with the static sites served by Netlify.
My Django has urls like
foobar.com/login/
foobar.com/dashboard/
etc.
Is it possible to use Netlify for a few static pages and my Django application for other pages?
I don't know how start or if this is event possible.
It will depend on how your Django apps handle the target, but you could use rewrites on Netlify using the HTTP status code 200 with a redirect rule (rewrite).
If the API supports standard HTTP caching mechanisms like Etags or Last-Modified headers, the responses will even get cached by CDN nodes.
Have DNS set foobar.com to the Netlify site.
Decide the domain for the Django site on AWS. (proxy.foobar.com)
Setup _redirects at the root of the Netlify site to use Proxy (rewrites) on Netlify
/login/* https://proxy.foobar.com/login/:splat 200
/dashboard/* https://proxy.foobar.com/dashboard/:splat 200
Note: This is how you can incrementally switch a site over to Netlify without having to refactor a site all at once.
When you set a DNS record (e.g. an A record), you can point foobar.com to your AWS server or netlify, but not both.
Perhaps you can put the sites on different domains, for example dashboard.foobar.com for your Django site.
You could then configure netlify to redirect foobar.com/dashboard/ to dashboard.foobar.com/dashboard/
No, you can't have a foobar.com point to two different servers. You'll have to use subdomains, e.g.:
static.foobar.com -> DNS entry for Netlify
app.foobar.com -> DNS entry for your Django server
or, what you often see, is:
foobar.com and www.foobar.com -> DNS pointing to your main website (Netlify)
api.foobar.com and app.foobar.com -> DNS pointing to your Django app
I'm trying to develop a PWA for our sites. In production and staging, we serve everything from one domain. However, in development on a local machine we serve HTML from one port using Django server eg
http://localhost:8000
And the assets (including JS) using Grunt server from another port:
http://localhost:8001
The problem is that the scope of the service workers is therefore only limited to assets, which is useless, I want to offline-cache pages on the 8000-port origin.
I have somewhat been able to go around this by serving the service worker as a custom view in Django:
# urls.py
url(r'^(?P<scope>.*)sw\.js', service_worker_handler)
# views.py
def service_worker_handler(request, scope='/'):
return HttpResponse(render_to_string('assets/sw.js', {
'scope': scope,
}), content_type="application/x-javascript")
However, I do not think this is a good solution. This code sets up custom routing rules which are not necessary for production at all.
What I'm looking for is a local fix using a proxy, or something else that would let me serve the service worker with grunt like all the other assets.
I believe this resource can be of help to you: https://googlechrome.github.io/samples/service-worker/foreign-fetch/
Basically you host the Service worker on the port 8001 and the server handles it as shown in the example.
Then you fetch it from there.
The Foreign fetch is described more in details here: https://developers.google.com/web/updates/2016/09/foreign-fetch
I've got a web app deployed on Dotcloud where the data on each page can be quite expensive to calculate (many seconds). I want to make initial page loads as speedy as possible by returning cached information and then hitting the server with a bunch of AJAX requests that cause the full calculations to occur. But I don't want these AJAX reqeusts to jam up initial page loads for other users, so I want them queuing separately.
I'm thinking the same Django app should be used for both servers, especially because the data model is shared. So the dotcloud.yml file would like kind of like:
www:
type: python
www-ajax:
type: python
(...)
But how can I route different URLs to each class of instances? Also, I've read about Gunicorn for long requests. These AJAX requests are long, but they don't depend on external resources, besides the DB. Is this a situation for Gunicorn, and if so, is there an easy way to integrate it into the config?
If you set it up the way you are describing in your example dotcloud.yml file, you will have two different services, with two different urls. So if you want to send stuff to the ajax service, you use the ajax url, if you want the regular one you can use the www url.
To run gunicorn you could use the python-worker user and allocate an http port for the python worker, and then have gunicorn listed on the http port. It is important to note that the python-worker doesn't have nginx in front of it like the python service, so gunicorn will need to be the one listening for the traffic directly.
So to put it together it would look something like this.
www:
type: python
approot: myapp
www-ajax:
type: python-worker
approot: myapp
ports:
www: tcp
process: gunicorn -b 0.0.0.0:$PORT_WWW yourapp:app
Your process string will most likely look different but you get the picture.
You also don't need the approot, just put it there as an example.