How to configure apache so html knows its aliases? - apache

I have 2 projects Symfony plus react.
They exist in 2 directories and react app uses Symfony app as api backend.
I tried to figure out the best way to connect it and I used Apache Alias
(/front -> my frontend directory because adding /api - backend dorectory broke backend )
Now..
Frontend app uses things like: .
I could add /front to url but i guess this isnlt right and my app shouldn't care what the aliases are.
What would be the best way to fix that?
Is there a way to configure it in apache or should I add some global variable before every url or is just putting front project inside backend project?

So basicly I bought a domain and created subdomain for backend and everything works well.

Related

Accessing the request object in nuxtJS module

I'm trying to create a nuxtJS module to make some changes to the routes based on the URL or request, i simply want to access the request.header.host inside a nuxtJS module but I'm unable to get it, i tried to check it process.server, this, context but unable to get the request object, i just want to get the full domain only, so how can I do that?
You can only get the hostname in the Browser JavaScript not internally in running nuxt app. As for nuxt app, it is running locally on the server (for example http://localhost:8080).
The information regarding hostname is present in services like Nginx/Apache.
Solution (One of them):
Use #nuxt/dotenv and store hostname in the environment variables:
hostname=example.com
then use wherever you want in your nuxt application with process.env.hostname

Dynamically change API route for SPA

I am currently building a SPA app using Vue.js and webpack to do our bundling. The backend API is built with .Net Core. When running locally, the Vue app is hitting localhost on the backend. I need to be able to change the route of the API dynamically based on the environment. Is there a way to do this without having to do a big switch statement that considers the current url? A requirement is that we are not allowed to change the webpack bundle for different environments, in other words, once it is bundled, it has to stay bundled. I have tried to pass static config files through to the bundle and dynamically change them based on the environment, but unfortunately that does not work, as it hits the values that were originally in them.
webpack dev server has a proxy capability. You could use this to proxy to your locally running backend when developing.
https://webpack.js.org/configuration/dev-server/#devserver-proxy
e.g. you can point anything from '/api' to 'localhost:8888/api' with the config.
Is your app the backend running on the same url when deployed? If not, you'll likely need a reverse proxy to pass along the requests to the backend.
You can use an axios interceptor so you only have that switch in one place:
axios.interceptors.request.use(config => {
// check location.host name and append the backend url you want
});
see https://github.com/axios/axios#interceptors
However, this is a little dangerous as the URLs in your switch statement will be strings, and therefore all of your environment URLs can be pulled out of your code even if minified/concatenated.
Another option is to add some sort of endpoint to the server your client side code is hosted, and when you start your app, query for that configuration.

Links in Express app missing API Gateway stage with Claudia JS

I've deployed a very basic Express app through Claudia JS. It's working pretty well, but any links or redirects don't keep the API Gateway stage and so don't work.
For example I have the app deployed at http://example.execute-api.eu-west-2.amazonaws.com/production - that's the equivalent of http://localhost:3000 when running locally. If there is a link on that page along the lines of <a href="/test"> that goes to http://localhost:3000/test locally, but through the api gateway it goes to http://example.execute-api.eu-west-2.amazonaws.com/test - losing the /production part of the URL and therefore not working.
Is there a way to get Express to know that all routes need to be prefaced with /production?
The alternate solution is to use a custom domain, but that seems like a lot of hassle to solve what seems like it should be just a bit of config.
You can use something like this to build the base URL;
https://${req.apiGateway.event.headers.Host}/${req.apiGateway.event.requestContext.stage}

rails angularjs html5mode webrick or nginx rewrite rule configure how?

i have angularjs app with html5mode enabled.
I have tried to run app in IE8 and it seems that URL is being prefixed with #! is it suppose to be - back button works etc..hashbang mode
I have tried to run app in modern browser and it seems that history api also work. All fine.
But if i hit http://localhost:3000/notes directly in address bar in both browsers i get routing error from webrick/rails app. I thought angular will take over of this request and handle it.
I have NOT setup anything on server side as angular guide say:
Using this mode requires URL rewriting on server side, basically you
have to rewrite all your links to entry point of your application
(e.g. index.html)
Is that why i am getting route error from webrick? And if i will able to setup rewriting rule how the hell it works? I thought if i rewrite something like http://localhost:3000/notes -> http://localhost:3000(index if u wish) the "/notes" - where i want to jump in is gone and angular app will never know where to route..
And if there is no way to tell webrick what and how to rewrite. How do you do in your development environment?
Thank you a lot.
You need to configure your server to return the same data for /notes as if it were the / route. Not a redirect (since that will remove notes). Basically you need a catchall route that returns if it doesn't match anything else. Either that or enumerate the known routes (i.e., /, /notes, /other, etc.), and have all of those return the same document. At that point, angular will detect the path and act accordingly.

Symfony2 multiple applications and api centric application

I'm trying to do a Symfony2 centric application and re-use all the Bundles for the web front app. The application will be divided in three API, FrontEnd, BackEnd, so that we can code the API like a Service Bundle and use it across the hole application and also will provide an API for our application. The FrontEnd will use the API as a Service and it will have all the front for user use. And the BackEnd will also use the API but providing a different url to admin the app.
This is the structure I'm using:
/app_api
/app_frontend
/app_backend
/bin
/src
/vendor
/web_api
/web_frontend
/web_backend
This will be traduced to:
api.domain.com (app_api, web_api)
www.domain.com (app_frontend, web_frontend)
backend.domain.com (app_backend, web_backend)
What do you think?
Is this posible?
What about performance, even if we are using APC?
If you have another solution let me know.
Thanks & Regards to everyone