Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
Connection refused error when fetching random images from Unsplash with SvelteKit

I want to make a website for my family company using SvelteKit. My current aim is to get a random nature image from Unsplash and make it the background image of the whole app. I set up the logic and I can get the image to show in the background but I get this error in the browser console, which repeats itself about every second:

GET http://localhost:3000/__vite_ping net::ERR_CONNECTION_REFUSED

Screenshot of the resulting page and console error

Here is index.svelte so far:

<script>
  const accessKey = 'MY_ACCESS_KEY';
  const url = 'https://api.unsplash.com/photos/random?query=nature&client_id=' + accessKey;

  fetch(url)
    .then((res) => {
      if (res.ok) return res.json();
      else alert(res.status);
    })
    .then((data) => {
      console.log(data);
      document.getElementsByTagName('div')[0].style.backgroundImage =
        'url(' + data.urls.regular + ')';
    });
</script>

<title>Küpeli Mühendislik •</title>

<div>
  <h1>Küpeli Mühendislik</h1>
  <p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
</div>

<style>
  @import url('https://fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700&display=swap');
  div {
    font-family: 'Lato', sans-serif;
    width: 95%;
    height: 100vh;
    margin: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
    /* background-color: #891f14; */
    color: aliceblue;
  }
</style>

There is also the warning at the top which I don't understand. And also I am guessing the additional background stylings should be added along with the image url and not inside the style tags, since they don't appear to be working.

Any insight would be appreciated. Thanks, Ugur.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

What you're seeing there is the hot module reloading/dev server for Vite trying to poll over that websocket (http://localhost:3000/__vite_ping), not actually a problem with fetching from unsplash.

I would confirm:

  1. Is the vite dev server running (probably launched with npm run dev)?
  2. Is it running on that port?

Look for the terminal where you started the dev server and look for any errors there as well.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda