How to add a url suffix while testing?

Viewed 38

I am making a url shortener and trying to open the link with their unique IDs stored on my database. This is my code for it:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.9.2/firebase-app.js";
import {
    getDatabase,
    ref,
    onValue
} from "https://www.gstatic.com/firebasejs/9.9.2/firebase-database.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
const firebaseConfig = {
    apiKey: "...",
    authDomain: "...",
    projected: "...",
    storageBucket: "...",
    messagingSenderId: "...",
    appId: "...",
};
const app = initializeApp(firebaseConfig);

const db = getDatabase();
const get = ref(
    db,
    "Urls/" +
        (window.location + "").split("/")[(window.location + "").split("/").length - 1]
);
console.log(((window.location + "").split("/")[(window.location + "").split("/").length - 1]))
onValue(get, (snapshot) => {
    window.location.href = snapshot.val().actualUrl
});

Now, according to this, my URL will look like this: link.shortly.com/uniqueLinkId(while testing, it will be fileLocation/link-opener.html/uniqueLinkId ), but this does not work while testing. When I give the URL this extra value, in the end, I get this error: enter image description here

I guess this issue will be gone when I host it, but I am testing it first before hosting.

Also, I would be glad if I could know how I can add extra value in these such cases.

0 Answers
Related