Open aefmind opened 3 years ago
@aefmind what are you using to access it via different hostname? Something like ngrok?
@flybayer No. I've hosted it in both OVH VPS (with Ubuntu and Debian) and in my Windows PC.
Even it fails when using 192.168.0.x IP address to access from local network (or same PC) to blitz app hosted in my Windows PC.
VPS has attached a domain.
@flybayer using ngrok, it also fails.
Doing SSH port forwarding (from port in remote server to a local port in my PC) makes it works by simply being able to access using localhost. But using IP address or domain, it has the infinite loop.
I've tried with blitz start -H <hostname>
whitout success.
@flybayer I managed to workaround this issue creating two files (dev.js and start.js) and running:
node dev.js
instead of blitz dev
node start.js
instead of blitz start
The contents of these files are:
start.js:
"use strict"
var _path = require("path")
var _startServer = require("next/dist/server/lib/start-server").default
const dir = (0, _path).resolve(".")
const port = 3000
const host = "domain.com"
const appUrl = `http://${host === '0.0.0.0' ? 'localhost' : host}:${port}`;
_startServer({ dir }, port, host)
.then(async (app) => {
console.log(`started server on ${host}:${port}, url: ${appUrl}`)
await app.prepare()
})
.catch((err) => {
console.error(err)
process.exit(1)
})
and dev.js:
"use strict"
var _path = require("path")
var _startServer = require("next/dist/server/lib/start-server").default
var _output = require("next/dist/build/output")
const dir = (0, _path).resolve(".")
const port = 3000
const host = "domain.com"
const appUrl = `http://${host === '0.0.0.0' ? 'localhost' : host}:${port}`;
_startServer(
{
dir,
dev: true,
isNextDevCommand: true,
},
port,
host
)
.then(async (app) => {
_output.startedDevelopmentServer(appUrl, `${host || "0.0.0.0"}:${port}`)
// Finalize server bootup:
await app.prepare()
})
.catch((err) => {
if (err.code === "EADDRINUSE") {
let errorMessage = `Port ${port} is already in use.`
console.error(errorMessage)
} else {
console.error(err)
}
process.nextTick(() => process.exit(1))
})
It is working fine. So the error is in blitz cli.
Thanks @aefmind for your help! We'll soon be removing the blitz cli wrapper, so probably this will be automatically fixed by that change then.
I ran into the same issue when using blitzjs in a kubernetes environment. I was able to work around it by manually specifying the host header in my service using the following nginx ingress annotation on the corresponding service:
nginx.ingress.kubernetes.io/upstream-vhost: "localhost:3000"
Maybe this helps some folks running in the same issue :) I guess this also applies to other environments allowing you to overwrite the host header.
Unfortunately this problem is still present in the newest version. @martinmuzatko is having the same problem.
@PumAmurcat can you open a new issue in the https://github.com/blitz-js/blitz repo?
I am also having this issue. I am using node v18.14.1 just FYI. I may help to get to a Minimum Working Example when I have time.
What is the problem?
Infinite loop in queries (
useQuery
,usePaginatedQuery
...). Problem is even present in a clean project generated byblitz new
command, accessing from custom domain.When using
blitz dev
, sometimes it stops after several reloads. But usingblitz build && blitz start
loop is always endless.Paste all your error logs here:
No errors are shown. But content is reloaded infinitely and server console show queries log. Example (in a clean
blitz new
project):Paste all relevant code snippets here:
Code needed to face the problem is the one generated by
blitz new
in app/pages/index.tsWhat are detailed steps to reproduce this?
Run
blitz -v
and paste the output here:UPDATED: