Comments (10)
Ah ok, that makes sense. Running miniflare
on your own network is definitely a use case I'd like to support, especially now that Miniflare 2 lets you run multiple miniflare
instances using the same (Redis) database and still maintain proper Durable Object transaction semantics. How about a function option like cfProvider
that accepts a Node request object and returns values for the cf
object and CF-*
headers? This would default to using the (cached) trustable HTTP endpoint, but could be customised to use a local IP database.
from miniflare.
What if we exposed a "trustable" HTTP endpoint to get the cf
object, then Miniflare could cache it in a file? If it fails to download, it would fallback to some hard-coded default.
This data doesn't change frequently, so the TTL could be really long.
from miniflare.
There you go! https://workers.cloudflare.com/cf.json
from miniflare.
There you go! https://workers.cloudflare.com/cf.json
Old thread -- but where is this URL officially documented?
from miniflare.
Hey! 👋 Thanks for making such a thorough feature request. I like this idea, and it's been suggested before, but I have a couple of questions/concerns:
- Where would we get the remote client IP address from? Presumably this would need to be a remote online service, breaking Miniflare's fully-offline promise. This probably isn't too much of a problem if this is an optional feature though.
- I'd like to avoid making a geo IP database like
fast-geoip
a hard dependency, as these tend to be pretty large and go against Miniflare 2's goal of being lightweight. Again, as you suggest, we could do this by passing a path to an already downloaded database, or we could just make it an optional peer dependency.
from miniflare.
That's a really good idea. Would automatically update if new fields are added to the cf
object too.
from miniflare.
Woah! That was quick! 🎉
from miniflare.
What if we exposed a "trustable" HTTP endpoint to get the
cf
object, then Miniflare could cache it in a file? If it fails to download, it would fallback to some hard-coded default.
This seems to me like a somewhat elegant and simple solution!
However, a local geoip database would certainly be "more offline" than this additional call to a worker.
I suppose the use case I imagine is this:
- You are running
miniflare
on your own publicly accessible edge network - Rather than completing an additional lookup, you would like IP info directly inline in the first request log
So fully completing the cf
object isn't necessarily the goal, but rather the extension of miniflare
as an edge services broker. Is this goal perhaps too tangential to the purpose of miniflare
?
from miniflare.
+1 to this feature. It is necessary for accurate development simulation.
Also necessary for self-hosting compatible Worker scripts off-Cloudflare, which should ideally be part of the goal of any open source project dealing with a single-vendor code execution environment.
These databases can be fairly large, so suggest ensuring the design allows for the memory object to be efficiently shared across multiple Miniflare instances.
from miniflare.
Hey! 👋 The first pre-release of Miniflare 2 has just been released, including this change. Request#cf
is now fetched from https://workers.cloudflare.com/cf.json and there's a new metaProvider
option that can be used for geo-IP lookups, assuming you're running Miniflare via its API:
const mf = new Miniflare({
async metaProvider(req) {
return {
forwardedProto: req.headers["X-Forwarded-Proto"],
realIp: req.headers["X-Forwarded-For"],
cf: {
// Could get these from a geo-IP database
colo: "SFO",
country: "US",
// ...
},
};
},
});
You can find the full changelog here and install it with npm i miniflare@next -D
. Please let me know if you have any other issues, and feel free to ask questions in the #miniflare
channel of the Cloudflare Workers Discord server.
from miniflare.
Related Issues (20)
- Node 21 vitest-environment-miniflare compatibility HOT 1
- [Miniflare 3] Step debugging with multiple workers HOT 2
- Update undici dependency due to vulnerability HOT 1
- [Docs] Miniflare v2 docs removed? HOT 3
- How to migrate Jest unit tests to Miniflare V3? HOT 1
- Support for typescript. HOT 1
- Is is it possible to collect coverage with vitest-environment-miniflare? HOT 2
- Increase better-sqlite3 compatibility HOT 1
- Uncaught error when initializing two top level WASM modules
- Multiple nodejs_compat packages missing (`crypto`, `path`, etc) HOT 4
- Fix CVE-2024-24758 HOT 3
- Type confusion HOT 1
- @miniflare/shared should not depend on @types/better-sqlite3 HOT 1
- Vitest bug: "Error: ENOENT: no such file or directory" HOT 2
- Workers: Error when an undefined value is exported in dev environment
- Type incompatibility issue between miniflare and workers-types HOT 4
- BUG: cannot install this library in node 22, please update better-sqlite3 HOT 1
- MiniflareCoreError [ERR_RUNTIME_FAILURE]: The Workers runtime failed to start. HOT 7
- How to test with `nodejs_compat` workers?
- How to use Worker's new native RPC feature? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from miniflare.