Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

325
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda