hashicorp / next-remote-watch

Decorated local server for next.js that enables reloads from remote data changes
Mozilla Public License 2.0
350 stars 19 forks source link

Problem when having next middleware #37

Closed gr-qft closed 2 years ago

gr-qft commented 2 years ago

First thanks for this great library, it's so useful for working with mdx files.

I've noticed that when having a middleware file,

import { NextRequest, NextResponse } from "next/server";

export function middleware(req: NextRequest) {
  const basicAuth = req.headers.get("authorization");

  if (basicAuth) {
    const auth = basicAuth.split(" ")[1];
    const [user, pwd] = Buffer.from(auth, "base64").toString().split(":");

    if (user === "xxx" && pwd === "xxxxxx") {
      return NextResponse.next();
    }
  }

  return new Response("Auth required", {
    status: 401,
    headers: {
      "WWW-Authenticate": 'Basic realm="Secure Area"',
    },
  });
}

Then running the watch command triggers the following error

 Error: To use middleware you must provide a `hostname` and `port` to the Next.js Server

But running just yarn dev doesn't cause any error.

Would really appreciate it if this can be looked into 👍 !

BRKalow commented 2 years ago

Closed by #35