How can the default route be removed on cloudfoundry using the manifest.yml - manifest

I define a route for my cloudfoundry app in its manifest file:
---
...
routes:
- route: example.com
My route gets successfully created during 'cf push' but unfortunately the default route gets created as well, i.e. I have two routes and I want only the one I defined in my manifest.
Any ideas how to get rid of the default route?
I know it is possible to remove routes, but as 'cf push' is triggered via a jenkins pipeline in my case I'd like to define everything in advance in the configuration. I assume that the manifest file is the best place to do so.
Even better would be if I can move the definition of the route into a manifest-variables file, but I'm trying it in the manifest file directly at the moment to be sure that this is not the source of my issue as I don't have much experience with it yet.
Thanks and beste regards,
Yvonne

This should work, I just tried this against Pivotal Web Services, for which CAPI is always kept pretty up to date (currently API version 2.142.0) and it worked just fine, only creating the route I specified. Which version of Cloud Foundry are you using? Also, I haven't checked if there is such a configuration but maybe your Cloud Foundry instance is configured to always create a route on the default shared domain.

One of the other possibilities is to use the commands unmap-route and map-route to map and unmap the routes of a specific application.

Related

How to serve static files of a service using path-based routing?

I've been searching for quite a while on many forums, how to serve static files referenced by HTML pages like href="/", when the frontend service isn't located at the root / of my host, using Nginx Ingress.
This question has been asked many times here, but briefly: I have a example.com/ host, and I need to expose a frontend service in a path like example.com/front1. This simply cannot work. The index.html returns perfectly, but then a href="/styles.css" hits the gateway asking for example.com/styles.css instead of example.com/front1/styles.css. And nginx just returns a 404.
The only "clean" solution I've found is to manage one subdomain for each frontend service, so it would request something like front1.example.com/styles.css. I'm afraid it might not be a great solution.
Some people do hacks like using sub filters annotations to replace href="/ strings with href="/front1/ for each file returned by that ingress and stuff like that, but this also falls short with dynamically javascript-generated pages and so on. And of course I can throw all my stuff in a S3 server, but think about it: If I have a cluster of many microfrontends and other third-party self-hosted frontend services (like signoz, which I have no control on the source code), it would be amazing if I could reference every service by its path like example.com/service-name/ and not worry about anything else.
I've been thinking of a possible solution in a lost comment of using nginx.ingress.kubernetes.io/server-snippet to inject some njs logic to replace the base URL by the Referer header (http://example.com/front1) whenever it references a known service, but I have no idea of how to use njs, if it is even possible, let alone if it is a good solution.
Anyway, my question is, has anyone solved that problem and could point me in the right direction? It is for a friend

Does code within NextJS API feature exposed to client side

It is well known that nextjs API routes provide a straightforward solution to build your API with Next.js. and that any file inside the folder pages/api is mapped to /api/* and will be treated as an API endpoint instead of a page.
I have just one doubt: is the code within the pages/api exposed to the world? I mean, can I build some logic there that has some key that must be hidden or maybe some MySQL connection?
Whether or not /api is in any way exposed to the world I do not know for sure, but according to Next documentation, "they are server-side only bundles."
In general though, for any key/sql connection that you want to run, I would put that into an .env.local file on your machine, a file that gets git ignored and never uploaded, and if you are hosting on Vercel, then use their environmental variables to store sensitive information.
You'd find environmental variables under:
{Your Account}/{Project}/Settings/Environmental Variables
p.s. Also from Next.js docs, I think you'd find this bit on getStaticProps useful.

Angular 8 Route Refresh gives 404 on Deployment Server

i am developing the application using Angular 8. I am facing an issue on the deployment server. When i make a build and deploy it to the server. If i go through its index point then its working fine but if i refresh any route then its giving me 404 error. kindly suggest me the best solution.
I implemented the hash strategy too on my local and checked on iis windows its working fine but i need some other method so that url will not look ugly. In this strategy a hash always would be there in the url.
So please tell is there any other way to do it.. without showing # in url..
Please experts help me to fix this as like angular.io because on that if you refresh any route then its work good without hashing strategy...
I usually use hash strategy but, as I know it is possibile to configure your server (for example via .htaccess file) in order to configure your routing. I don't know how by the way.

Best practice for handling api key in Play framework

I am trying to build a website with the Play framework that will need to request some directions from the google maps api.
For those requests, I need to use my google api key. Obviously, I don't want to hardcode this value for multiple reasons. Is there a specific file configuration file that is suited for this usage in the Play framework?
It sounds like you don't want to hardcode your key for security reasons - ie. you are checking into a public Github repository, in which case you have a couple of options:
I usually use an environment variable for local development:
maps.api.key=${?MAPS_API_KEY}
ie. where MAPS_API_KEY is an environment variable configured on your machine.
For production deployment I either:-
1.) Set the value dynamically at build time from a private property file. Usually my approach if using a CI tool for the build.
2.) You could also pass it in as a system variable at startup:
/path/to/yourapp/bin/yourapp -Dmaps.api.key="YOURKEY"
You will need to modify your startup script if using activator dist to create your distribution.

Restlet - serving up static content

Using Restlet I needed to serve some simple static content in the same context as my web service. I've configured the component with a Directory, but in testing, I've found it will only serve 'index.html', everything else results in a 404.
router.attach("/", new Directory(context, new Reference(baseRef, "./content"));
So... http://service and http://service/index.html both work,
but http://service/other.html gives me a 404
Can anyone shed some light on this? I want any file within the ./content directory to be available.
PS: I eventually plan to use a reverse proxy and serve all static content off another web server, but for now I need this to work as is.
Well, I figured out the issue. Actually Restlet appears to route requests based on prefix, but does not handle longest matching prefix correctly, it also seems to ignore file extensions.
So for example, if I had a resource attached to "/other"... and a directory on "/". And I request /other.html, what actually happens is I get the "/other" resource. (The extension is ignored?), and not the static file from the directory as I would expect.
If aynone knows why this is, or how to change it, I'd love to know. It's not a big deal, just for testing. I think we'll be putting apache or nginx in front of this in production anyway.
Routers in Restlet by default use the "Template.MODE_STARTS_WITH" matching mode. You could always set the Router default by doing router.setMatchingMode(Template.MODE_EQUALS). This will turn on strict matching by default for attach. You can choose to override individual routes with setMatchingMode.
Good documentation on Restlet Routing