infeeeee / kimai2-cmd

Command line client for Kimai2, the open source, self-hosted time tracker
MIT License
24 stars 6 forks source link

fix trailing slash problem in server url #1

Closed kevinpapst closed 5 years ago

kevinpapst commented 5 years ago

When entering a URL like

kimaiurl=http://127.0.0.1:8050/

this will lead to calls like this:

op:  {
  url: 'http://127.0.0.1:8050//api/timesheets/active',
  headers: { 'X-AUTH-USER': 'susan_super', 'X-AUTH-TOKEN': 'api_kitten' },
  method: 'GET'
}

Notice the double slash between host and path. Symfony doesn't accept such URLs and returns a 404. The PR will prevent/hide this simple human config mistake. So users can enter both URL versions with and without trailing slash.

As answer I received errors like:

? Select command List active measurements
undefined:1
<!DOCTYPE html>
^

SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at Request._callback (/Users/kevin/Development/kimai2-cmd/kimai2-cmd.js:54:32)
    at Request.self.callback (/Users/kevin/Development/kimai2-cmd/node_modules/request/request.js:185:22)
    at Request.emit (events.js:196:13)
    at Request.<anonymous> (/Users/kevin/Development/kimai2-cmd/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:196:13)
    at IncomingMessage.<anonymous> (/Users/kevin/Development/kimai2-cmd/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:284:20)
    at IncomingMessage.emit (events.js:201:15)
    at endReadableNT (_stream_readable.js:1130:12)

At least in development mode, the API doesn't answer JSON friendly if there is a double slash in the URL.

BTW: nice project!

infeeeee commented 5 years ago

Wow, thank you! As I tested always typed the url correctly :)

kevinpapst commented 5 years ago

It was the first thing I saw when trying the tool ;-) I really like the idea of using the command line. There are a lot of possible use-cases for that, so thanks for starting this one! If you think this is stable, please let me know, I'd like to feature it in the store

infeeeee commented 5 years ago

Yes I want to add there, before Kimai2 1.0 will be out. This client is not finished yet, but I think it's already usable in this state.

Around when will you reach 1.0? Do you have a deadline?

kevinpapst commented 5 years ago

This will be hard, as I want to release it today ;-)

infeeeee commented 5 years ago

Then I will add later, I thought I have some more weeks. Now I just checked that the windows build doesn't work so I wouldn't advertise this client in this state yet.

kevinpapst commented 5 years ago

You know: after the release is before the release ;-) Some companies wait for a 1.0 to trust that its stable for production... so why wait?!