arjndr
arjndr

Reputation: 124

ExpressJS only accepts POST 6 times?

I have an ElectronJS app to play music and I was working on a "Remote" that I can use to control my app through other devices via a browser.

I used ExpressJS and Socket.IO, but whatever I do, play, pause, next-track or previous-track, everything does work but only 6 times, i.e If I press the play-pause button 6 times, it stops working for the 7th time. Here's the code I use on the client(Remote)

  $('#previous').click(function () {
    $.post('/prevsong')
  })

  $('#playpause').click(function(){
    $.post('/playpause')
  })

  $('#next').click(function () {
    $.post('/nextsong')
  })

And this is the code I use on the ElectronJS app

app.post('/playpause', function () {
  // Play Pause audio tag in the Electron app
})    

app.post('/nextsong', () => {
  // Next Song Code
})

app.post('/prevsong', () => {
  // Previous Song Code
})

I'm new to ExpressJS and server side stuff, what am I doing wrong? How can I fix this issue?? Thanks!

Upvotes: 2

Views: 180

Answers (1)

arjndr
arjndr

Reputation: 124

I fixed the issue by replacing app.post with app.get, if anyone else is experiencing the same issue, here's what I did

  app.get('/playback/:key', (request, response, next) => {
    response.send(request.params.key + ' button pressed');
    // Do something
  })

And then this on the client

  $('#previous').click(function () {
    $.get('/playback/prevsong')
  })

  $('#playpause').click(function(){
    $.get('/playback/playpause')
  })

  $('#next').click(function () {
    $.get('/playback/nextsong')
  })

Upvotes: 1

Related Questions