Api Proxy for production
-
Hi all,
According to the doc Api Proxy, this api proxy only work for development environment. But what if I need to use in production too?I found out on setting the production url on this doc, the problem is that all my axios instance already wrote with api word as start
this.$axios.get('/api/something/new')
,I wouldnt want to rewrite all the axios like
this.$axios.get(process.env.API+'/api/something/new')
I got search github and this forum about proxy, but almost all are refer old quasar.
-
in production you use reverse proxy (nginx, haproxy or others) and you are set.
-
@qyloxe
Hi thx for your answer, then I would like to ask where should I define the base url in quasar app for production? -
@geoffreylzf best practice: base url === domain name.
-
If you’re going to use an external api, you can use an extension such as qenv or dotenv and set a variable such as:
API=http://my-production-api
in you dev env andAPI=https://my-dev-api
in your prod envThen just set that as the base url for axios under src/boot/axios.js
axios.defaults.baseURL = process.env.API;
-
Thank you very much