dev (#1)
All checks were successful
Build Urlshort / publish (push) Successful in 1m29s

Reviewed-on: #1
Co-authored-by: fede <federico.nicolas.polidoro@gmail.com>
Co-committed-by: fede <federico.nicolas.polidoro@gmail.com>
This commit was merged in pull request #1.
This commit is contained in:
2026-03-18 16:33:48 -03:00
committed by fedpo
parent b00ed96b9e
commit e9566dcc62
5 changed files with 44 additions and 26 deletions

View File

@@ -1,18 +1,6 @@
<script>
import { url } from "./assets/hooks/getUrl";
import AcortadorForm from "./assets/lib/AcortadorForm.svelte";
$effect(
(async () => {
if (window.location.pathname.match(/^\/short\/url\/\d+$/)) {
const numero = window.location.pathname.split("/").pop();
// console.log(numero);
const res = await fetch(`${$url}/url/${numero}`, {
method: "GET",
});
console.log(res);
}
})(),
);
</script>
<section id="center">

View File

@@ -8,6 +8,6 @@ export const url = readable(
export const redirect = readable(
typeof window !== "undefined" && window.location.hostname === "localhost"
? "http://localhost:5173/short"
? "http://localhost:8080/"
: "https://fedesrv.ddns.net/s",
);

View File

@@ -13,16 +13,16 @@
onsubmit={async (e) => {
e.preventDefault();
// console.log(e.target[0].value);
// console.log(input);
console.log($url);
const req = { longUrl: input.value };
try {
const res = await fetch($url + "/url", {
const res = await fetch(`${$url}/url/`, {
method: "POST",
body: JSON.stringify({ ...req }),
});
if (res.ok) {
const data = await res.json();
// console.log(data.shortUrl);
console.log(data.shortUrl);
popup = data.shortUrl;
}
} catch {
@@ -30,21 +30,33 @@
}
}}
>
<button type="reset"></button>
<input type="text" id="acortadorinput" />
<button type="submit"></button>
</form>
{#if popup}
<div transition:fade class="popup-dialog">
<p>Short URL creada</p>
<button
onclick={() => {
navigator.clipboard.writeText(`${$redirect}/url/${popup}`);
popup = "";
}}
>
Copy</button
>
{#if popup == "Error"}
<p>Fallo al crear la url</p>
<button
onclick={() => {
popup = "";
}}
>
Cerrar</button
>
{:else}
<p>Short URL creada</p>
<button
onclick={() => {
navigator.clipboard.writeText(`${$redirect}/url/${popup}`);
popup = "";
}}
>
Copiar</button
>
{/if}
</div>
{/if}
@@ -82,4 +94,8 @@
.popup-dialog button:hover {
background-color: #0056b3;
}
button,
input {
padding: 0.25rem;
}
</style>