Skip to content

Commit

Permalink
make sure that @opennextjs/cloudflare can be used in projects with …
Browse files Browse the repository at this point in the history
…`type` set to `module`
  • Loading branch information
dario-piotrowicz committed Oct 2, 2024
1 parent 3628be6 commit 18586b9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "api",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "next build",
Expand Down
4 changes: 3 additions & 1 deletion packages/cloudflare/src/cli/templates/worker.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import NextNodeServer, { NodeRequestHandler } from "next/dist/server/next-server";
import { NodeNextRequest, NodeNextResponse } from "next/dist/server/base-http/node";
import { AsyncLocalStorage } from "node:async_hooks";
import { type CloudflareContext } from "../../api";
import type { IncomingMessage } from "node:http";
import { MockedResponse } from "next/dist/server/lib/mock-request";
import type { NextConfig } from "next";
import type { NodeRequestHandler } from "next/dist/server/next-server";
import Stream from "node:stream";

const NON_BODY_RESPONSES = new Set([101, 204, 205, 304]);
Expand Down Expand Up @@ -35,6 +35,8 @@ export default {
return cloudflareContextALS.run({ env, ctx, cf: request.cf }, async () => {
if (requestHandler == null) {
globalThis.process.env = { ...globalThis.process.env, ...env };
// eslint-disable-next-line @typescript-eslint/no-require-imports
const NextNodeServer = require("next/dist/server/next-server.js");
requestHandler = new NextNodeServer({
conf: { ...nextConfig, env },
customServer: false,
Expand Down

0 comments on commit 18586b9

Please sign in to comment.