Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: implement url shortener service #1

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Feat: implement url shortener service #1

wants to merge 16 commits into from

Conversation

DimaOsinnii
Copy link
Owner

@DimaOsinnii DimaOsinnii commented May 26, 2024

Tasks:

  • create basic layout using picocss
  • implement form with svelte enhance for creating short url
  • integrate cloudflare Pages & KV
  • implement collection request data during redirecting from short url
  • create short url stats page
  • create list of all created short urls

Copy link

cloudflare-workers-and-pages bot commented May 27, 2024

Deploying url-shortener with  Cloudflare Pages  Cloudflare Pages

Latest commit: a5bb3fe
Status: ✅  Deploy successful!
Preview URL: https://0a727cfc.url-shortener-2gj.pages.dev
Branch Preview URL: https://task.url-shortener-2gj.pages.dev

View logs

src/routes/+page.server.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,57 @@
<script lang="ts">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be invalidation on reload, I think its not nice to cache stats page (you make few clicks, go to stats page and its empty)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do invalidateAll in onMount on each dynamic data page - /shortUrl/stats and /list but nothing changed. I also check without cache in the browser and from incognito tabs. I think the problem is in Cloudflare KV, the latency from write to read is too big, and i read few post and KV docs where people said that it can be happed, maybe because of hot and cold reads.

So i think maybe Cloudflare KV is not perfect match for this kind of task or maybe it need to be used as a cache, not storage

https://developers.cloudflare.com/kv/reference/how-kv-works/
https://community.cloudflare.com/t/delay-in-workers-kv/149463

src/routes/+page.server.ts Outdated Show resolved Hide resolved
@nosovk
Copy link

nosovk commented Jun 3, 2024

try to put as url:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzA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Qei66PfyuRj4Ik9is+hglfbkbfR3cnZm7chlUWLdwmprtCohX4HUtlOcQjLYCu+fzGJH2QRKvP3UNz8bWk1qMxjGTOMThZ3kvgLI5AzFfo379UAAAAASUVORK5CYII=

src/lib/index.ts Outdated Show resolved Hide resolved
refactor form action, page

remove unnecessary errors; create validation for create url form data; remove field configs instead create union type
@DimaOsinnii DimaOsinnii closed this Jun 7, 2024
@DimaOsinnii DimaOsinnii reopened this Jun 7, 2024
Comment on lines +20 to +28
try {
parsedUrl = new URL(url);
} catch (_) {
throw new CreateUrlError('url', 'Invalid URL');
}

if (!allowedProtocols.includes(parsedUrl.protocol)) {
throw new CreateUrlError('url', 'Only HTTP and HTTPS URLs are allowed');
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read about URL.canParse method, but i need also check protocol of the actual url and canParse does not allowe this, so the solution was bettwen native api and regexp i choose first approach

@DimaOsinnii DimaOsinnii requested a review from nosovk June 7, 2024 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants