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

324
Vistas
React and Ably, getting 404 cannot GET /publish and /subscribe error on voting tutorial

I am following this tutorial

I am a little lost with getting Ably working for realtime connections.

Everything compiles without error but I start getting 404's in console for the /publish and /subscribe URL's. I get that it is failing on the code in my server.js file (I assume in the realtime auth createTokenRequest), which is as follows:

const app = express();
app.use(cors());
const realtime = Ably.Realtime({
     key: process.env.ABLY_API_KEY,
});

app.use(express.static(path.join(__dirname, 'testext/build')));

app.get("/publish", (request, response) => {
    const tokenParams = {
       capability: '{"*":["publish"]}',
};
realTimeAuth(tokenParams, response);
});

app.get("/subscribe", (request, response) => {
    const tokenParams = {
         capability: '{"*":["subscribe"]}',
};
realTimeAuth(tokenParams, response);
});

const realTimeAuth = (tokenParams, response) => {
   realtime.auth.createTokenRequest(tokenParams, function (err, tokenRequest) {
    if (err) {
        response
            .status(500)
            .send("Error requesting token: " + JSON.stringify(err));
    } else {
        // return the token request to the front-end client
        response.json(tokenRequest);
    }
});
};

const listener = app.listen(process.env.PORT, () => {
    console.log("App is listening on port " + listener.address().port);
});

Any help on why the error is happening would be much appreciated.

about 4 years ago · Juan Pablo Isaza
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