Using Capacitor, how can I prevent quasar forcing the dev server to an external IP? #15936
-
|
For Android development, I'd prefer to use the adb reverse proxy so that the dev server is accessed via localhost on the device. This gives me the following benefits:
I'm currently achieving this by running the following: Where patch-quasar.js simply removes the offending code from the library. This is not ideal. How can I do this without having to hack the code? patch-quasar.js: const fs = require('fs')
const path = require('path')
// Here we remove code from the quasar library that forces the host to be an external IP.
const filePath = path.join('node_modules', '@quasar', 'app-vite', 'lib', 'quasar-config-file.js')
const codeToRemove = ` else if (
[ 'cordova', 'capacitor' ].includes(mode)
&& (!host || [ '0.0.0.0', 'localhost', '127.0.0.1', '::1' ].includes(host.toLowerCase()))
) {
const getExternalIP = require('../lib/helpers/get-external-ip')
host = await getExternalIP()
this.chosenHost = host
}\n`
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err)
return
}
const updatedData = data.replace(codeToRemove, '')
fs.writeFile(filePath, updatedData, 'utf8', (err) => {
if (err) {
console.error('Error writing file:', err)
}
})
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
I also have the same problem/request @rstoenescu, would it be possible to allow capacitor mode to run on localhost? |
Beta Was this translation helpful? Give feedback.
-
This point is solved in app-vite v3(not released yet) through using capacitor.config.js/ts, and a wrapper under the hood which passes the used settings(e.g. ip, cleartext, etc.) via env variables. |
Beta Was this translation helpful? Give feedback.
This point is solved in app-vite v3(not released yet) through using capacitor.config.js/ts, and a wrapper under the hood which passes the used settings(e.g. ip, cleartext, etc.) via env variables.