fastify / fastify/fastify-nextjs

There is no host in the middleware of nextjs

Open
#612 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
558
Forks
62
Avg merge
2d 4h
Merged PRs (30d)
6

Description

### Prerequisites

- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported

### Fastify version

9.0.0

### Plugin version

_No response_

### Node.js version

v16.10.0

### Operating system

Linux

### Operating system version (i.e. 20.04, 11.3, 10)

CentOS Linux 7 (Core)

### Description

When the host of listen is set to '0.0.0.0', the host obtained by the middleware of nextjs is empty, which causes the nextjs middleware to report an error

### Steps to Reproduce

```js
// import next from 'next';
import fastifyFactory from 'fastify';
import FastifyNextJS from '@fastify/nextjs';
// import {parse} from 'url';
// import { ParsedUrlQuery } from 'querystring';
// import { NextUrlWithParsedQuery } from 'next/dist/server/request-meta';

const port = parseInt(process.env.PORT as string, 10) || 8000;
const dev = process.env.NODE_ENV !== 'production';
// const app = next({ dev })

const fastify = fastifyFactory({logger: false, pluginTimeout: dev ? 120_000 : undefined});
fastify
.register(FastifyNextJS)
.after(() => {
fastify.next('/*', (app, req, reply) => {
return app.getRequestHandler()(req.raw, reply.raw).then(() => {
reply.hijack();
})
})
});

const start = async () => {
try {
await fastify.listen({
port,
host: '0.0.0.0',
exclusive: false,
readableAll: false,
writableAll: false,
ipv6Only: false
});
console.log(`server start at port: ${port}`);
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
};
start();

```
### Expected Behavior

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.