Skip to content

There is no host in the middleware of nextjs #612

Open
@yantingxi

Description

@yantingxi

Prerequisites

  • I have written a descriptive issue title
  • 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

// 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions