@miniflare/http-server
Advanced tools
Comparing version 2.0.0-rc.1 to 2.0.0-rc.2
@@ -29,3 +29,2 @@ var __defProp = Object.defineProperty; | ||
import { Headers } from "undici"; | ||
import { WebSocketServer } from "ws"; | ||
@@ -539,2 +538,4 @@ // packages/http-server/src/helpers.ts | ||
} | ||
const ws = await import("ws"); | ||
const WebSocketServer = ws.WebSocketServer ?? ws.default.WebSocketServer; | ||
const webSocketServer = new WebSocketServer({ noServer: true }); | ||
@@ -545,4 +546,4 @@ const liveReloadServer = new WebSocketServer({ noServer: true }); | ||
if (pathname === "/cdn-cgi/mf/reload") { | ||
liveReloadServer.handleUpgrade(request, socket, head, (ws) => { | ||
liveReloadServer.emit("connection", ws, request); | ||
liveReloadServer.handleUpgrade(request, socket, head, (ws2) => { | ||
liveReloadServer.emit("connection", ws2, request); | ||
}); | ||
@@ -558,5 +559,5 @@ } else { | ||
} | ||
webSocketServer.handleUpgrade(request, socket, head, (ws) => { | ||
void coupleWebSocket(ws, webSocket); | ||
webSocketServer.emit("connection", ws, request); | ||
webSocketServer.handleUpgrade(request, socket, head, (ws2) => { | ||
void coupleWebSocket(ws2, webSocket); | ||
webSocketServer.emit("connection", ws2, request); | ||
}); | ||
@@ -566,7 +567,7 @@ } | ||
const reloadListener = () => { | ||
for (const ws of liveReloadServer.clients) { | ||
ws.close(1012, "Service Restart"); | ||
for (const ws2 of liveReloadServer.clients) { | ||
ws2.close(1012, "Service Restart"); | ||
} | ||
for (const ws of webSocketServer.clients) { | ||
ws.close(1012, "Service Restart"); | ||
for (const ws2 of webSocketServer.clients) { | ||
ws2.close(1012, "Service Restart"); | ||
} | ||
@@ -573,0 +574,0 @@ }; |
{ | ||
"name": "@miniflare/http-server", | ||
"version": "2.0.0-rc.1", | ||
"version": "2.0.0-rc.2", | ||
"description": "HTTP server module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers", | ||
@@ -39,8 +39,8 @@ "keywords": [ | ||
"dependencies": { | ||
"@miniflare/core": "2.0.0-rc.1", | ||
"@miniflare/shared": "2.0.0-rc.1", | ||
"@miniflare/web-sockets": "2.0.0-rc.1", | ||
"@miniflare/core": "2.0.0-rc.2", | ||
"@miniflare/shared": "2.0.0-rc.2", | ||
"@miniflare/web-sockets": "2.0.0-rc.2", | ||
"kleur": "^4.1.4", | ||
"selfsigned": "^1.10.11", | ||
"undici": "^4.9.3", | ||
"undici": "^4.10.2", | ||
"ws": "^8.2.2", | ||
@@ -50,5 +50,5 @@ "youch": "^2.2.2" | ||
"devDependencies": { | ||
"@miniflare/shared-test": "2.0.0-rc.1", | ||
"@miniflare/shared-test": "2.0.0-rc.2", | ||
"@types/node-forge": "^0.10.4" | ||
} | ||
} |
# `@miniflare/http-server` | ||
HTTP server module for [Miniflare](https://github.com/cloudflare/miniflare): a | ||
fun, full-featured, fully-local simulator for Cloudflare Workers | ||
fun, full-featured, fully-local simulator for Cloudflare Workers. See | ||
[🧰 Using the API](https://miniflare.dev/api.html) for more details. | ||
## Example | ||
```js | ||
import { CorePlugin, MiniflareCore } from "@miniflare/core"; | ||
import { | ||
HTTPPlugin, | ||
convertNodeRequest, | ||
createServer, | ||
startServer, | ||
} from "@miniflare/http-server"; | ||
import { VMScriptRunner } from "@miniflare/runner-vm"; | ||
import { Log, LogLevel } from "@miniflare/shared"; | ||
import { MemoryStorage } from "@miniflare/storage-memory"; | ||
import http from "http"; | ||
// Converting Node.js http.IncomingMessage to Miniflare's Request | ||
http.createServer(async (nodeReq, nodeRes) => { | ||
const req = await convertNodeRequest(nodeReq, "http://upstream", { | ||
forwardedProto: "http", | ||
realIp: "127.0.0.1", | ||
cf: { colo: "SFO" }, | ||
}); | ||
nodeRes.end(await req.text()); | ||
}); | ||
// Creating and starting HTTP servers | ||
export class BadStorageFactory { | ||
storage() { | ||
throw new Error("This example shouldn't need storage!"); | ||
} | ||
} | ||
const plugins = { CorePlugin, HTTPPlugin }; | ||
const ctx = { | ||
log: new Log(LogLevel.INFO), | ||
storageFactory: new BadStorageFactory(), | ||
scriptRunner: new VMScriptRunner(), | ||
}; | ||
const mf = new MiniflareCore(plugins, ctx, { | ||
modules: true, | ||
script: `export default { | ||
async fetch(request, env) { | ||
return new Response("body"); | ||
} | ||
}`, | ||
port: 5000, | ||
}); | ||
// Start the server yourself... | ||
const server = await createServer(mf); | ||
// ...or get Miniflare to start it for you, logging to port | ||
const server2 = await startServer(mf); | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38011
690
61
+ Added@miniflare/core@2.0.0-rc.2(transitive)
+ Added@miniflare/shared@2.0.0-rc.2(transitive)
+ Added@miniflare/web-sockets@2.0.0-rc.2(transitive)
- Removed@miniflare/core@2.0.0-rc.1(transitive)
- Removed@miniflare/shared@2.0.0-rc.1(transitive)
- Removed@miniflare/web-sockets@2.0.0-rc.1(transitive)
Updated@miniflare/core@2.0.0-rc.2
Updated@miniflare/shared@2.0.0-rc.2
Updatedundici@^4.10.2