diff --git a/.changeset/fair-pillows-yawn.md b/.changeset/fair-pillows-yawn.md new file mode 100644 index 000000000..6258ffa21 --- /dev/null +++ b/.changeset/fair-pillows-yawn.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/aws": patch +--- + +fix(expres-dev): Ensure x-forwarded-proto and \_\_NEXT_PRIVATE_ORIGIN is set diff --git a/packages/open-next/src/overrides/wrappers/express-dev.ts b/packages/open-next/src/overrides/wrappers/express-dev.ts index ae2fcd6b4..14bc9fc91 100644 --- a/packages/open-next/src/overrides/wrappers/express-dev.ts +++ b/packages/open-next/src/overrides/wrappers/express-dev.ts @@ -34,6 +34,12 @@ const wrapper: WrapperHandler = async (handler, converter) => { }); app.all("*paths", async (req, res) => { + if (req.protocol === "http" && req.hostname === "localhost") { + // This is used internally by Next.js during redirects in server actions. We need to set it to the origin of the request. + process.env.__NEXT_PRIVATE_ORIGIN = `${req.protocol}://${req.hostname}`; + // This is to make `next-auth` and other libraries that rely on this header to work locally out of the box. + req.headers["x-forwarded-proto"] = req.protocol; + } const internalEvent = await converter.convertFrom(req); const streamCreator: StreamCreator = { writeHeaders: (prelude) => {