A powerful, self-hosted link shortener built with SvelteKit and Cloudflare D1.
Follow these steps to deploy your own instance of UFO Link Shortener.
npm install -g wranglerClone the repository and install dependencies:
git clone https://github.com/xanthisafk/cf-redirect-svelte.git
cd cf-redirect-svelte
npm install
Create a D1 Database:
npx wrangler d1 create cf-redirect
Copy the database_id from the output.
Configure wrangler.jsonc:
cp wrangler.jsonc.demo wrangler.jsonc
wrangler.jsonc and replace Your <database_id> goes here with the ID you just generated.Apply Migrations: Create the necessary tables in your remote D1 database:
npx wrangler d1 migrations apply cf-redirect --remote
(For local development, use --local flag).
Open wrangler.jsonc and update the vars section with your secrets and configuration:
"vars": {
"JWT_SECRET": "generate-a-long-random-string-here",
"PROMO_MODE": "public", // 'public' or 'private'
"MAX_USERS": "100",
"MAX_LINKS_PER_USER": "50",
// Analytics Features
"TRACK_LOCATION": "true",
"TRACK_DEVICE": "true",
"TRACK_OS": "true",
"TRACK_BROWSER": "true",
"TRACK_REFERRER": "true"
}
Security Note: Never commit your real
wrangler.jsoncor.envfiles to version control if they contain secrets.
Deploy your application to Cloudflare Workers:
npm run deploy
Your app will be live at https://cf-redirect.<your-subdomain>.workers.dev (or your custom domain).
To run the application locally (using a local D1 emulator):
Apply Local Migrations:
npx wrangler d1 migrations apply cf-redirect --local
Start Preview Server:
npm run preview --remote
# OR for purely local dev (requires build):
npm run build && wrangler dev
| Command | Description |
|---|---|
npm run dev |
Start Vite dev server (frontend only, may lack D1 context) |
npm run preview --remote |
Build and run with Miniflare (simulates Worker env) |
npm run deploy |
Deploy to Cloudflare |
npx wrangler d1 migrations apply cf-redirect --local |
Update local database schema |
npx wrangler d1 migrations apply cf-redirect --remote |
Update remote database schema |
MIT