I built a large hybrid NuxtJS (v3) app that uses SSR and nitro pre-render. Many of the pages make api calls during pre-render. Many of the pages content depends on lots of api calls to data that doesn’t change much. All api calls (anything starting with /api
) are proxied with NuxtJS server in server/middleware/proxy.ts
to hide the api. During pre-render NUXT_PUBLIC_BASE_URL
is localhost:3000
. I have a custom build server setup that runs a proxy during build.
The problem is i need to replace all the http://localhost:3000
values with production domain (i.e. https://demo.example.com
) after the build is complete since i can’t build from production server and the hard-coded domain in the pre-rendered pages needs to be changed to the production domain.
If i serve the build with node .output/server/index.mjs
and then curl -v http://localhost:3000
i get a complete html body. If i change the urls (i tried many different ways) and run node .output/server/index.mjs
and curl -v http://localhost:3000
i get broken html (end of out put looks like }</script></bo
)
One way I change url is with find .output/public -type f -name "*.html" -exec sed -i 's|http://localhost:3000|https://demo.example.com|g' {} +
. or find .output/public -type f -name "*.html" -exec sh -c 'sed "s|http://localhost:3000|https://demo.example.com|g" "$1" > tmpfile && mv tmpfile "$1"' _ {} ;
or even used replace-in-file
and had same problem. I’ve tested in other apps and see same problem, after doing replace, html served is incomplete.
I don’t understand why this results in a broken output from curl -v http://localhost:3000
after restarting the app. What is causing this? How do i make the replacement without having to render the domain with SSR during live request?