-
Notifications
You must be signed in to change notification settings - Fork 0
add server script #1
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
Conversation
n-batrakov
left a comment
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.
👍
scripts/server.js
Outdated
| * @param {http responce} response | ||
| */ | ||
| let getStream = response => filename => fs | ||
| .createReadStream(`./${filename}`) |
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.
Думаю, здесь можно указать просто .createReadStream(filename).
Так немного чище, а результат равнозначный. Плюс т.о. мы позволяем вызывать функцию с абсолютными путями
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.
- 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."); |
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.
Опечатка:
Error! Can't read file 'index.html'. Check that file exists & correct.
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.
- done
scripts/server.js
Outdated
| let showHelp = () => void console.log(` | ||
| Welcome to server.js script! This script run the server. | ||
|
|
||
| You can use agruments: |
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.
Общепринятым названием, думаю, будет options.
Принято разделять аргументы (arguments) и опции (options). Аргументы - порядковы, опции - именованные. Например,
program argument1 argument2 --option1 value --option2=value
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.
- done
scripts/server.js
Outdated
| index => { | ||
| if (isNaN(index)){ | ||
| console.error(color('red'), 'Index must be a Number. For more information use --help'); |
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.
Я правильно понимаю, что index здесь это номер порта?
Если так, то, думаю, в сообщении стоит отразить это. Как пользователю, мне было бы не очень понятно такое сообщение об ошибке.
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.
- done
scripts/server.js
Outdated
| index => { | ||
| if (isNaN(index)){ | ||
| console.error(color('red'), 'Index must be a Number. For more information use --help'); |
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.
Лишний пробел в
Index must be a Number. For more information
^
😄
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.
- done
scripts/server.js
Outdated
| } | ||
| return index || 3000; | ||
| } | ||
| )(agrv); |
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.
Не очень понимаю, почему здесь указываются аргументы.
Разве так не получается, что getPort это значение, а не функция? Аналогично с getFile и getHelp
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.
- done
scripts/server.js
Outdated
| let agrv = process.argv.slice(2); | ||
| getHelp(agrv); | ||
| let port = getPort(agrv); | ||
| createServer(serverCallback(getFile(agrv)))(port).listen(port) |
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.
Мне довольно сложно читать это.
Думаю, стоит выделить дополнительные переменные или т.п.
Интересным вариантом записать это было бы:
let server = pipe(
getFile,
serverCallback,
createServer,
)(argv)
server(port).listen(port)
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.
- done
No description provided.