Skip to content

Paylicier/stalk

Repository files navigation


Packt Logo

Stalk

A Cloudflare Worker that tracks your location, resolves it to points of interest (POIs) using OpenStreetMap, or maps it to defined "hidden zones" (like Home or Work) and serve it via an api.

Setup

  1. Install Dependencies

    bun install
  2. Configure Wrangler Ensure you have a wrangler.toml file configured with your Cloudflare account details. You will need:

    • A KV Namespace bound as LOC_KV.
    • A HIDDEN_ZONES variable (can be set via .dev.vars for local development or secrets for production).
    • USER and PASS variables for updating location
  3. Environment Variables

    • HIDDEN_ZONES: A JSON string defining your private zones.
      [
        {  "name": "Home", "lat": 18.300615, "lon": -64.825609, "radius": 0.5 },
        {  "name": "Office", "lat": 44.380642140432165, "lon": -73.22706310693646, "radius": 0.2 }
      ]]
    • USER: Username (HTTP basic auth)
    • PASS: Password (HTTP basic auth)

Development

Start the local development server:

bun run dev

Deployment

Deploy to Cloudflare Workers:

bun run deploy

Usage

Update Location (POST)

Send a JSON payload to the worker root:

POST /

Content-Type: application/json

Headers: Authorization: U3RhclRoaXNSZXBvUHdlYXNlOlN1cGVyU2VjcmV0UGFzc3dvcmQ=

{
  
  "lat": 48.8579,
   "lon": 2.2948,
   "batt": 85,
   "bs": 1
}}

You can use an app OwnTracks (Android / iOS) to periodically send your location to the api

Get Current Status (GET)

Retrieve the last known location and battery level:

GET /

Response:

{
   "location": "Eiffel Tower (Paris, France)",
   "battery": 85,
   "batteryStatus": 1
}}

About

Cloudflare worker to serve your current location via an api

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published