AMP not working in Custom server
Unanswered
Dwarf Crocodile posted this in #help-forum
Dwarf CrocodileOP
Hello,
I used to run my development environment using the default next run dev command, and the AMP version of my project worked fine. However, after switching to a custom Next.js server, the AMP stopped working and now only shows an HTML page without any styling.
For your information, I am currently using Next.js 14.2.3. When I switched back to Next.js 13.1.6 while using the custom server, AMP worked correctly. I suspect it's a problem with Next.js 14.
Specs:
- Next.js 14.2.3
- React.js 18.3.1
- Pages route
Here is my custom server code:
I used to run my development environment using the default next run dev command, and the AMP version of my project worked fine. However, after switching to a custom Next.js server, the AMP stopped working and now only shows an HTML page without any styling.
For your information, I am currently using Next.js 14.2.3. When I switched back to Next.js 13.1.6 while using the custom server, AMP worked correctly. I suspect it's a problem with Next.js 14.
Specs:
- Next.js 14.2.3
- React.js 18.3.1
- Pages route
Here is my custom server code:
const { loadEnvConfig, processEnv } = require("@next/env")
const loadedEnvConfig = loadEnvConfig(dirname, false)
processEnv(loadedEnvConfig.loadedEnvFiles)
process.env.NODE_ENV = "development"
process.chdir(dirname)
const { createServer } = require("http")
const { parse } = require("url")
const next = require("next")
const dev = true
const hostname = process.env.HOSTNAME || "localhost"
const port = parseInt(process.env.PORT, 10) || 3000
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()
app.prepare().then(() => {
createServer(async (req, res) => {
try {
// Be sure to passtrueas the second argument tourl.parse.
// This tells it to parse the query portion of the URL.
const parsedUrl = parse(req.url, true)
await handle(req, res, parsedUrl)
} catch (err) {
console.error("Error occurred handling", req.url, err)
res.statusCode = 500
res.end("internal server error")
}
})
.once("error", (err) => {
console.error(err)
process.exit(1)
})
.listen(port, () => {
console.log(\x1b[32m\x1b[1m> πππ Ready on http://${hostname}:${port} \x1b[0m)
})
})1 Reply
Dwarf CrocodileOP
Anyone?