← Back to context

Comment by tiffanyh

2 years ago

This is excellent!

Would you mind open sourcing the code for that?

This is the code running this endpoint:

  export function onRequest(context) {
    return new Response(JSON.stringify([parseFloat(context.request.cf.longitude), parseFloat(context.request.cf.latitude)]), {headers: {"Content-Type": "application/json;charset=UTF-8"}})
  }

This is a function on Cloudflare Pages (which is just a different name for Cloudflare Workers). Minor adjustment needed for Workers (get rid of "context", I believe)