-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop #127
base: master
Are you sure you want to change the base?
Develop #127
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimal improvement suggestions. Noice!
src/createServer.js
Outdated
return; | ||
} | ||
|
||
if (req.url === '/compress' && req.method === 'GET') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message from the error and the test are not aligned here.
Your are testing if the method is GET
, and the error says you allow only POST
.
So, what's the problem? If someone sent a PUT
, would this test block it? Nope.
Is PUT
the same as POST
? Also nope.
So, the test you are looking for is: req.method !== 'POST'
src/createServer.js
Outdated
compressorType = zlib.createDeflate(); | ||
} else { | ||
res.statusCode = 400; | ||
res.end('unsupported compression type'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This else will never run, so you can remove it.
It won't ever run, because the if in line 43 of your code already tests it.
The same reasons that would make the test fail here are the ones that make it fail before, so it will never reach this point
src/createServer.js
Outdated
`attachment; filename=${file[0].originalFilename}.${compressionType[0]}`, | ||
); | ||
|
||
let compressorType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but you could try:
declaring your previous Object literal here, might work just like this, but better:
const compressors = {
gzip: zlib.createGzip,
br: zlib.createBrotliCompress,
deflate: zlib.createDeflate,
};
const compressorType = compressors[compressionType[0]]();
See how I did not call the functions inside the compressors
object, but only in compressorType
, after I already know which will be used.
And, if you store this compressors
object before line 43, you can even replace !['gzip, 'br', 'deflate'].includes...
for !Object.keys(compressors).includes...
Allowing your coed to be easily extendable later on(you would only need to change the compressors
object)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flawless!
No description provided.