Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!