I am creating a web app where, this app will generate a .html file in public/
directory. And after that i want to show that generated html file
on a page using iframe
.
I am using NextJS
for this task. I have configured next.config.js
for rewrites
but getting 404 error
. I am using Railway for hosting. Since in Vercel we can not access filesystem here.
Instead of generating html dynamically, if I upload that .html file, then i can access that file using iframe
in production.
I think we can not access those files which were not available during build process. (this is my guess , maybe wrong)
How can I solve this problem or should I use another framework ? Thanks
Since I was accessing .html files (i.e
<iframe src="path-to-file"></iframe>
) which were not available duringbuild
process, that's why i was getting404 error
.So I did the following thing: suppose I want to do this
<iframe src="/pdf/page01.xhtml"></iframe>
where file location is inpublic/pdf/page01.xhtml
.so this
src
is sending aGET
request tolocalhost:3000/pdf/page01.xhtml
. To manipulate thisrequest
I created apages/api/pdf/[...slug].js
. In this file you can useprocess.cwd()
to access the file inside yourpublic
dir. You read file content usingfs.readFile
and send the responseres.status(200).send(data)
like this.By doing this I was getting the desired result.
Suggestions are always welcome.