https://github.com/spences10/sveltekit-short-urls
Short URLs with SvelteKit
https://github.com/spences10/sveltekit-short-urls
short-url short-urls svelte sveltekit vercel
Last synced: 2 months ago
JSON representation
Short URLs with SvelteKit
- Host: GitHub
- URL: https://github.com/spences10/sveltekit-short-urls
- Owner: spences10
- Created: 2022-01-29T18:58:36.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-13T09:49:57.000Z (about 1 year ago)
- Last Synced: 2024-04-13T21:09:32.720Z (about 1 year ago)
- Topics: short-url, short-urls, svelte, sveltekit, vercel
- Language: TypeScript
- Homepage: https://sveltekit-short-urls.vercel.app/links
- Size: 1.18 MB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SvelteKit Short URLs
A modern URL shortener built with SvelteKit and Turso (libSQL).
Features link management, click tracking, and referrer analytics.## Features
- Short URL creation and redirection
- Click tracking and analytics
- Referrer tracking
- Web interface for viewing active links
- Position-based link ordering
- Visibility controls for links## Database Schema
The application uses Turso (libSQL) with two main tables:
### Links Table
- `id`: Unique identifier
- `source`: Short URL path
- `destination`: Target URL
- `position`: Order position
- `description`: Link description
- `clicks`: Click counter
- `visible`: Visibility flag### Referrers Table
- Tracks traffic sources for each link
- Maintains count of visits per referrer## Setup
1. Create a Turso database and obtain credentials
2. Set environment variables:
```bash
TURSO_DB_URL=your_database_url
TURSO_DB_AUTH_TOKEN=your_auth_token
TURSO_SYNC_URL=your_sync_url # Optional
```## Database Operations
### Adding a Link
```sql
INSERT INTO links (source, destination, description, visible, position)
VALUES ('key', 'https://destination.com', 'Description', true, 1);
```### Updating a Link
```sql
UPDATE links
SET destination = 'new-url', description = 'new description'
WHERE source = 'key';
```### Deleting a Link
```sql
DELETE FROM links WHERE source = 'key';
```### Viewing Links
```sql
-- All visible links
SELECT * FROM links WHERE visible = true;-- Most clicked links
SELECT source, destination, clicks
FROM links
ORDER BY clicks DESC
LIMIT 10;-- Top referrers
SELECT r.referrer, SUM(r.count) as total_referrals
FROM referrers r
GROUP BY r.referrer
ORDER BY total_referrals DESC
LIMIT 10;
```## Development
```bash
# Install dependencies
pnpm install# Run development server
pnpm dev# Run tests
pnpm test
```## Security Features
- Server-side database operations only
- No client-side fetch operations
- Secure redirect handling
- Environment variable protection