Next.js Discord

Discord Forum

Cannot Access the Content of _next/ When Using a Custom Server

Answered
Pond loach posted this in #help-forum
Open in Discord
Pond loachOP
Hello everyone! I am new to Next.js. I have built a custom server where Next.js's request handler would be run. It can render pages, however, all the relevant CSS and JS files are at a _next/static/something/something URL instead. If a quick HTTP request to those URLs returns the content from there, then it is alright. However, instead of returning those content, the rendered page from app/page.jsx is returned instead, as if Next.js thought the app router should handle that HTTP request instead of Next.js's server itself. So, a normal CSS file imported into a page would result in the errors in the attached image. Why is all this happening? The problem happens when Next.js's request handler is being run, when Next.js has full control over the request and response objects, so the fact that it is in a custom server should not be a problem. How can this be fixed?
Answered by Pond loach
Never mind, I changed the backend code from app.use(handler); to app.use((req, res) => handler(req, res)); and the problem disappeared
View full answer

9 Replies

Pond loachOP
For example, a page like this
Will generate HTML containing this CSS file
And the content of the CSS file is the page itself
@Pond loach For example, a page like this
Pond loachOP
Note: This page is /app/page.jsx
@Pond loach Note: This page is /app/page.jsx
ohhhh. yeah the css isnt meant to be accessed directly
there probably is a way programmatically, but i dont know it off the top of my head. if you just want to look at it yourself you should be able to see it in dev tools
Pond loachOP
Never mind, I changed the backend code from app.use(handler); to app.use((req, res) => handler(req, res)); and the problem disappeared
Answer