I've developed vue js front end and I could communicate backend using axios call and when I call I need to specify backend service port and endpoint. how can I use nginx and docker and then after I use nginx and docker how app communicate with backend ? ultimately I need to deploy front end and backend services on kubernetes cluster.
I've read many tutorial about this and I don't have clear idea in concept and also need to implement the solution. I have never use nginx before
Backend : http://localhost:8084
Here is my axios call
import axios from 'axios'
const API_URL = 'http://localhost:8084'
class NotificationDataService {
retrieveAllNotifications() {
return axios.get(`${API_URL}/notification/getall`);
}
}
export default new NotificationDataService()
with Docker (and thus Kubernetes) approach you have to separate the container from your Frontend and the container from your Backend.
In Kubernetes you can use an Ingress. It is a reverse proxy, so you don't need Nginx. https://kubernetes.io/docs/concepts/services-networking/ingress/
To configure the URL of your Backend in your Vue.js application, I advise you not to use a constant variable as you do, but the configuration system of the Framework: https://cli.vuejs.org/guide/mode-and-env.html#modes.
You need to expose your frontend and backend with your Ingress, because your Axios calls are sent from the client to the backend. So you could have :
www.mydomain.com/ for your Frontend
www.mydomain.com/api for your backend
And now your frontend has only made calls to www.mydomain.com/api.
Translated with www.DeepL.com/Translator (free version)
Related
Does anyone knows how I am supposed to manage Nuxt & axios configuration with a multi-tenant API built with django-rest-framework and django-tenants (https://github.com/django-tenants/django-tenants)?
This API is reachable by tenant subdomain: tenant1.example.com/api, tenant2.example.com/api, ... (within my dev environment: tenant1.localhost:8000/api, tenant2.localhost:8000/api, ...)
In my Nuxt app, I want to use #nuxtjs/axios and #nuxtjs/auth-next.
→ How can I proxy axios API URL to take into account the API subdomains (tenant1.example.com/api, ...)?
→ How can I configure auth endpoints (tenant1.example.com/api/login, ...)?
Thanks for your help!
I am working in micro front end approach using single-spa-angular framework.I have a root container application which runs in 4200 port and 2 micro apps say app1 #5201 and app2 # 4201 port. I am not facing any issues with app2 and its working perfectly as per micro front end approach.
In app1, I have a login component and dashboard component. so when i hit the app1 it hits the login component first (desired flow: it has to check the user profile and authenticate and based on the result it will navigate to dashboard component). For checking this user profile in app1, I am running backend services using application server (which runs #8443 port) and proxy is configured in proxy config.json like this:
{
"/app1/*": {
"target": "http://localhost:8443/",
"secure": false
}
}
and during npm start in app1 it picks up this statement ( --proxy-config proxy.conf.json) from package .json and this is how we configure proxy for backend services in app1.
Now,coming to micro front end, when I hit app1 from root container, I am getting an access denied image instead of dashboard. Internally ,It hits the login component of app1, when I see the network tab, it hits the user-profile method with the 200k status, but the response is the whole html (whatever i have given in index.html of root container) and an access denied image is called and rendered.It is not hitting the backend server itself.
But when I hit http://localhost:5201/app1/app1/app1-user-profile, I am able to see the desired response in the browser.so what is preventing me to get dashboard of app1 when i route from other apps/4200 port?
Can anyone please guide me in this regard? should i need to configure Proxy settings in root container and other micro apps as well ? Can single-spa help me in this proxy configuration?
I had the same problem , my solution was to configure the proxy in the root application, in my case it was a webpack dev configuration.
It is because all the routes which are not defined explicitely in the route component of your "subapp" are redirected by the root application.
Here is my webpack config with the proxy for example
https://github.com/milobella/application-web/blob/master/portal/webpack.dev.js
If you are facing issues in handling proxy inside single-spa angular and your are coming from angular background, trying your app migrate to the micro frontend or working with single-spa , here is the solution which will work like a charm.
Remind that, we cannot serve proxy.config.json just like we used to do in our angular app.
Here, we need to take of proxy config inside the webpackconfig.js of our host or shell or root-config app.
Here is an example,
For better idea, refer my blog : How to handle proxy inside single-spa angular
official docs : Webpack proxy configuration
How to connect frontend to backend?
The site was Laravel 5.7 + VUE. Now was completely written from scratch in JS frontend (self-written).
I. e. it is necessary to leave the old backend (Laravel 5.7) + API and connect the new frontend to it.
As I understand it, you need to rewrite the old backend for a new frontend or not?
New frontend only. The task is to connect the old backend and API to the new frontend.
It's not necessary to rewrite your backend, in fact a would try to leave it as it is, and just try to connect new frontend with existing backend API (endpoints). Or is there any specific reason for changing the backenend codebase?
VUE is a Javascript frontend framework and Laravel is a framework for PHP so you do not need to rewrite the backend. What you need to do is configure your frontend to match the
Laravel codebase in the backend.
I have an Ionic 3 web app where I'm using Laravel for both the API and the back-end manager with Nova. Ideally, I'd like my setup to be:
Server 1: example.com serving only my static Ionic App
Server 2: api.example.com serving my Laravel API
Server 2: example.com/admin serving my Laravel backend with Nova
This is easy with Laravel forge, except that I want api.example.com and example.com/admin to be powered by the same application. Right now it looks like I would need my code to live as two separate applications, one for api. and one for /admin.
It makes sense that there would be a way to configure Nginx to point both to the same place, but how, and which one, and where?
I solved this with a redirect from /admin to the appropriate destination. You can either do this in nginx or in Ionic.
I want to use Golang as the server and Nuxt as the frontend, I googled it around but couldn't find any examples.
Code for express/node.js that i found out in the nuxt + express. Link is below
const express = require('express')
// Create express instnace
const app = express()
// Require API routes
const users = require('./routes/users')
// Import API Routes
app.use(users)
// Export the server middleware
module.exports = {
path: '/api',
handler: app
}
I can just create golang server api and deploy it as a microservice but will I lose the SSR power of nuxt? as in will google still crawl my web pages if i use a separate server as opposed to monolithic version of nuxt + node.js
link: https://github.com/nuxt-community/express-template
Regards
You should just separate them. One server is for your backend api in golang. Other server is node server for nuxt ssr. Then you can use nginx to route requests to desired server based on path or anything. And everything will work