works in node and browser - #64
Conversation
|
I needed to replace the required modules: |
|
Hi @u-rogel 👋 Thanks for looking into this! I've just converted the PR to a draft for you while it's still in-progress. It looks like the only lingering question left is the retrying on timeouts? |
|
Reply to @liammclennan from the issue #61 @KodrAus thanks for labelling it as draft. Yes, working out the timeouts retry is still missing. Will need to check if it can be done easily on both envs or do we need to search for some other solution. |
|
Timeout handling added. |
liammclennan
left a comment
There was a problem hiding this comment.
Thanks @u-rogel. This PR is getting close. I've added some comments to address some issues and to provide support back to node 14.
| let url = require('url'); | ||
|
|
||
| const NodeBlob = require('buffer').Blob | ||
| const GlobalBlob = Blob !== undefined ? Blob : NodeBlob |
There was a problem hiding this comment.
this fails in older node. Try typeof(Blob) !== 'undefined'
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "X-Seq-ApiKey": this._apiKey ? this._apiKey : null, |
There was a problem hiding this comment.
In my testing this is not working properly. X-Seq-ApiKey: null causes this error 'Payload from [...] specified invalid API key ·····'
There was a problem hiding this comment.
How did you test it?
Do you guys using your test-suits?
| this._lastRemoteConfig = null; | ||
|
|
||
| this._httpModule = this._endpoint.protocol === "https:" ? https : http | ||
| this._httpAgent = new this._httpModule.Agent({ |
There was a problem hiding this comment.
the reference to _httpAgent on line 96 causes a crash
| const HEADER_FOOTER_BYTES = Buffer.byteLength(HEADER, 'utf8') + Buffer.byteLength(FOOTER, 'utf8'); | ||
|
|
||
| const HEADER_FOOTER_BYTES = (new GlobalBlob([HEADER])).size + (new GlobalBlob([FOOTER])).size | ||
|
|
There was a problem hiding this comment.
fetch can be polyfilled by referencing node-fetch@2 and then something like:
const fetchApi = typeof(fetch) === 'undefined' ? require('node-fetch') : fetch;
then it works in node 16
There was a problem hiding this comment.
Slightly different approach but done!
|
|
||
| return new Promise((resolve, reject) => { | ||
| const sendRequest = (batch, bytes) => { | ||
| const controller = new AbortController() |
There was a problem hiding this comment.
To support node 14 we must handle missing AbortController.
Something like:
const controller = typeof(AbortController) === 'undefined'
? () => ({ abort: () => {} })
: new AbortController();There was a problem hiding this comment.
I think better to use the abort-controller since we can provide the same functionality.
|
I think I found a workaround missing packages in the browser. |
| return this.flush().then(() => { | ||
| this._httpAgent.destroy(); | ||
| }); | ||
| return this.flush().then(() => {}); |
There was a problem hiding this comment.
the .then(() => {}) doesn't do anything you can just:
return this.flush();
|
@liammclennan thanks! |
|
@u-rogel Won't be this week. I'm still tidying up a few things, fixing the tests, and making sure it works everywhere. As soon as that is done I will publish the package. Thanks for this work, and for your patience through the process. |
|
@liammclennan no rush, I will use my own branch till then. Another mini contribution is for future development, would be great to add something like this to the example folder or something similar for spinning up a seq-server: version: '3'
services:
seq:
image: datalust/seq:latest
deploy:
resources:
limits:
memory: 14G
reservations:
memory: 14G
# volumes:
# - /datadrive:/data
environment:
- ACCEPT_EULA=Y
ports:
- 80:80
- 5341:5341
expose:
- 80
- 5341
labels:
- traefik.backend=seq
- traefik.frontend.rule=Host:seq.<snip>.com
- traefik.port=80 |
|
Thanks @u-rogel Something like that might be nice. |
This is only a draft, but works.