Skip to content

Conversation

@xenikopa
Copy link
Owner

@xenikopa xenikopa commented Apr 8, 2020

No description provided.

@xenikopa xenikopa requested a review from n-batrakov April 8, 2020 12:14
Copy link
Collaborator

@n-batrakov n-batrakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* @param {http responce} response
*/
let getStream = response => filename => fs
.createReadStream(`./${filename}`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Думаю, здесь можно указать просто .createReadStream(filename).
Так немного чище, а результат равнозначный. Плюс т.о. мы позволяем вызывать функцию с абсолютными путями

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • done

let getStream = response => filename => fs
.createReadStream(`./${filename}`)
.on('error', () => {
console.log(color('red'), "Error! Can't read file 'index.html'. Check, that file is exists & correct.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опечатка:

Error! Can't read file 'index.html'. Check that file exists & correct.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • done

let showHelp = () => void console.log(`
Welcome to server.js script! This script run the server.

You can use agruments:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Общепринятым названием, думаю, будет options.

Принято разделять аргументы (arguments) и опции (options). Аргументы - порядковы, опции - именованные. Например,

program argument1 argument2 --option1 value --option2=value

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • done

Comment on lines 55 to 57
index => {
if (isNaN(index)){
console.error(color('red'), 'Index must be a Number. For more information use --help');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я правильно понимаю, что index здесь это номер порта?

Если так, то, думаю, в сообщении стоит отразить это. Как пользователю, мне было бы не очень понятно такое сообщение об ошибке.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • done

Comment on lines 55 to 57
index => {
if (isNaN(index)){
console.error(color('red'), 'Index must be a Number. For more information use --help');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лишний пробел в

Index must be a Number.  For more information
                       ^

😄

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • done

}
return index || 3000;
}
)(agrv);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не очень понимаю, почему здесь указываются аргументы.

Разве так не получается, что getPort это значение, а не функция? Аналогично с getFile и getHelp

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • done

let agrv = process.argv.slice(2);
getHelp(agrv);
let port = getPort(agrv);
createServer(serverCallback(getFile(agrv)))(port).listen(port)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мне довольно сложно читать это.
Думаю, стоит выделить дополнительные переменные или т.п.

Интересным вариантом записать это было бы:

let server = pipe(
  getFile,
  serverCallback,
  createServer,
)(argv)

server(port).listen(port)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • done

@xenikopa xenikopa merged commit 8cbd8ac into master Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants