Skip to content

Repository files navigation

YouBike Locator

Locate the nearest YouBike without having to visit YouBike's website or app.

Open the page, allow location access, and it shows the closest station that actually has a bike to rent — with distance, walking time, a live count split into regular and electric bikes, free docks, and a one-tap link to directions.

The regular/electric split matters: about half of all stations hold both models at once, so a single "bikes" number does not tell you whether you are getting a pedal bike or an e-bike.

How it works

YouBike publishes a single public JSON feed of every station in Taiwan (~9,500 stations, ~6 MB). Shipping that to the browser on each visit would be wasteful, so the feed never leaves the server:

  • src/lib/stations.ts (server-only) fetches the feed and keeps it in an in-process cache with a 60-second TTL, matching how often YouBike refreshes. Concurrent requests share one in-flight fetch, and a failed refresh falls back to the last good snapshot rather than erroring.
  • src/app/api/nearest/route.ts takes lat and lng, does the distance maths server-side, and returns only the handful of stations that matter (~1.5 KB).
  • src/app/page.tsx is the client component: it asks for the browser's location, calls that endpoint, and renders the result.

The feed is deliberately kept out of the Next.js data cache, whose per-entry size limit a 6 MB payload comfortably exceeds.

Getting started

npm install
npm run dev

Open http://localhost:3000.

Location services require a secure context: localhost works, but any other host needs HTTPS.

Configuration

No environment variables are required. YOUBIKE_API can optionally override the feed URL — see .env.example.

Scripts

Command Purpose
npm run dev Development server
npm run build Production build
npm run start Serve the production build
npm run lint ESLint

Deploying

The app is a stock Next.js project with no external services, so vercel --prod (or connecting the repo on Vercel) is all that is needed.

About

Locate the nearest YouBike without having to visit YouBike's website or app

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages