Hi,
FYI, this is my first pull request ever and my js experience is minimal. Please feel free to pinpoint anything that may be violating the best practices of a pull request!
On the subject now, I have first noticed that the VF request example as shown in both README.MD and index.html files does not include the MMSI parameter:
Then I have tried the request manually and noticed that the headers were not as expected for the VF request. Namely, the 'User-agent' header was commented out (I assume to allow the MT request to execute properly). However, the specific header is needed for the VF request. As a result, the VF-specific request was broken and the universal getLastPostion request was actually a MT-only request.
After fixing the above by using separate header objects for each request type, I have noticed an issue in getLastPosition at the lines where moment is used:
const vfDate = moment(VFResult.data.timestamp); const mtDate = moment(MTResult.data.timestamp);
The issue comes from the fact that moment tries to interpret a timestamp of the following format:
Sun Mar 21 2021 12:04:00 GMT+0200 (Eastern European Standard Time)
The message in the console is as follows:
_Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.Arguments:
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, i: Sun Mar 21 2021 12:04:00 GMT+0200 (Eastern European Standard Time), _f: undefined, _strict: undefined, locale: [object Object]
Error
at Function.createFromInputFallback (c:\ais-api\nodemodules\moment\moment.js:319:25)
.........................................................................................................
So I decided to use the toISOString() function instead of toString() in lines 71 and 136 of the api.js. That may break the code of other developers who potentially may be parsing the specific value downstream.
Hi, FYI, this is my first pull request ever and my js experience is minimal. Please feel free to pinpoint anything that may be violating the best practices of a pull request! On the subject now, I have first noticed that the VF request example as shown in both README.MD and index.html files does not include the MMSI parameter:
Then I have tried the request manually and noticed that the headers were not as expected for the VF request. Namely, the 'User-agent' header was commented out (I assume to allow the MT request to execute properly). However, the specific header is needed for the VF request. As a result, the VF-specific request was broken and the universal getLastPostion request was actually a MT-only request. After fixing the above by using separate header objects for each request type, I have noticed an issue in getLastPosition at the lines where moment is used:
const vfDate = moment(VFResult.data.timestamp); const mtDate = moment(MTResult.data.timestamp);
The issue comes from the fact that moment tries to interpret a timestamp of the following format:
Sun Mar 21 2021 12:04:00 GMT+0200 (Eastern European Standard Time)
The message in the console is as follows: _Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info. Arguments: [0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, i: Sun Mar 21 2021 12:04:00 GMT+0200 (Eastern European Standard Time), _f: undefined, _strict: undefined, locale: [object Object] Error at Function.createFromInputFallback (c:\ais-api\nodemodules\moment\moment.js:319:25) .........................................................................................................
So I decided to use the toISOString() function instead of toString() in lines 71 and 136 of the api.js. That may break the code of other developers who potentially may be parsing the specific value downstream.
At your disposal for further clarifications