feat: terminada funcionalidad

actualmente funciona en dev falta cocinar deploy
This commit is contained in:
2026-03-17 11:18:22 -03:00
parent 5906cae45e
commit 68ce52f7c8
7 changed files with 87 additions and 12 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
front/node_modules
shorturls.db

View File

@@ -1,7 +1,18 @@
<script>
import { url } from "./assets/hooks/getUrl";
import AcortadorForm from "./assets/lib/AcortadorForm.svelte";
import svelteLogo from "./assets/svelte.svg";
import viteLogo from "./assets/vite.svg";
$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

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

View File

@@ -1,7 +1,9 @@
<script>
import { url } from "../hooks/getUrl";
import { fade } from "svelte/transition";
import { redirect, url } from "../hooks/getUrl";
let input;
let popup = $state("");
$effect(() => {
input = document.getElementById("acortadorinput");
});
@@ -20,11 +22,64 @@
});
if (res.ok) {
const data = await res.json();
console.log(data.shortUrl);
// console.log(data.shortUrl);
popup = data.shortUrl;
}
} catch {
popup = "Error";
}
} catch {}
}}
>
<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
>
</div>
{/if}
<style>
.popup-dialog {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: var(--bg);
border: var(--border) 1px solid;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
z-index: 1000;
text-align: center;
}
.popup-dialog p {
margin: 0 0 15px 0;
font-size: 16px;
color: var(--text);
}
.popup-dialog button {
background-color: #007bff;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
.popup-dialog button:hover {
background-color: #0056b3;
}
</style>

View File

@@ -6,11 +6,11 @@ export default defineConfig({
plugins: [svelte()],
server: {
proxy: {
"/url": {
target: "http://localhost:3000",
"/short/": {
target: "http://localhost:8080",
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/url/, ""),
rewrite: (path) => path.replace(/^\/short/, ""),
},
},
},

View File

@@ -23,7 +23,7 @@ func main() {
db.AutoMigrate(&models.Url{})
http.HandleFunc("/url", func(w http.ResponseWriter, r *http.Request){
http.HandleFunc("/url/", func(w http.ResponseWriter, r *http.Request){
routes.Url(w, r, db)
})

View File

@@ -34,8 +34,9 @@ func Url(w http.ResponseWriter, r *http.Request, db *gorm.DB) {
longUrl, err := repository.RecuperarUrl(paths[len(paths)-1], db)
if err != nil {
http.Error(w, "Error: "+err.Error(), http.StatusBadRequest)
return
}
http.Redirect(w, r, longUrl, http.StatusPermanentRedirect)
http.Redirect(w, r, longUrl, http.StatusMovedPermanently)
default:
http.Error(w, "404", http.StatusBadGateway)