Skip to content
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

[#85] make the port number configurable #126

Merged
merged 5 commits into from
Aug 7, 2022

Conversation

Kariel-Myrr
Copy link
Contributor

@Kariel-Myrr Kariel-Myrr commented Jul 19, 2022

Description

Motivation:
Server port wasn't configurable.
We want to be able specify it via cmd line option or environment variable

Solution:
Implement configuration by cmd option(stronger) & env variable for port

  • in lib:
    • added serverOption
    • added lookup for env var 'COFFER_SERVER_PORT'
  • in tests -> server-integration
    • added cmd option with 8081 port
    • added tests for port configuration (tests based on 8079 port)

Related issue(s)

Fixed #85

✅ Checklist for your Pull Request

Related changes (conditional)

  • Tests

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from
      silently reappearing again.
  • Documentation

    • I checked whether I should update the docs and did so if necessary:

Stylistic guide (mandatory)

@Kariel-Myrr Kariel-Myrr force-pushed the kariel-myrr/#85-make-the-port-number-configurable branch 2 times, most recently from 508c2e0 to f901572 Compare July 20, 2022 23:23
@Kariel-Myrr Kariel-Myrr marked this pull request as ready for review July 20, 2022 23:27
@Kariel-Myrr Kariel-Myrr requested a review from dcastro July 20, 2022 23:27
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
coffer.cabal Outdated Show resolved Hide resolved
tests/server-integration/Common/BootServer.hs Show resolved Hide resolved
tests/server-integration/Common/BootServer.hs Outdated Show resolved Hide resolved
tests/server-integration/Common/BootServer.hs Outdated Show resolved Hide resolved
tests/server-integration/Common/BootServer.hs Outdated Show resolved Hide resolved
tests/server-integration/Common/BootServer.hs Outdated Show resolved Hide resolved
tests/server-integration/Common/BootServer.hs Outdated Show resolved Hide resolved
lib/Web/Main.hs Outdated Show resolved Hide resolved
lib/Web/Main.hs Outdated Show resolved Hide resolved
lib/Web/Main.hs Outdated Show resolved Hide resolved
@Kariel-Myrr Kariel-Myrr requested a review from dcastro July 26, 2022 20:18
@Kariel-Myrr Kariel-Myrr requested a review from sancho20021 August 3, 2022 11:11
Copy link
Member

@dcastro dcastro left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

Copy link
Contributor

@sancho20021 sancho20021 left a comment

Choose a reason for hiding this comment

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

What about taking some default port if none of the env var and option is set?

deriving stock (Eq)

instance Show RunServerException where
show (RunServerIncorrectPort port) = "Port number should be greater than 0. Your port number is: " ++ show port
Copy link
Contributor

Choose a reason for hiding this comment

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

Port number should be from 0 to 65536 is a bit clearer

Copy link
Member

Choose a reason for hiding this comment

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

Or just don't check the range at all - just pass the port number to servant and let servant do the check.

lib/Web/Main.hs Show resolved Hide resolved
lib/Web/Main.hs Outdated Show resolved Hide resolved
lib/Web/Main.hs Outdated Show resolved Hide resolved
lib/Web/Main.hs Outdated Show resolved Hide resolved
@dcastro dcastro mentioned this pull request Aug 3, 2022
@dcastro
Copy link
Member

dcastro commented Aug 6, 2022

@sancho20021 is no longer working on this project, so I marked his comments as resolved.

I think it's good to be merged now @Kariel-Myrr 👍

Problem:
Server boots on one hardcoded port

Solution:
- added opportunity to boot it on specified port 
- added way to set port by option or env var
Problem:
now `runServer` requires port number
so have to add it to tests

Solution:
- add env argument for port number 8081
- remove redundant .config
Problem:
Add new functionality 
Now we can config port via:
- cmd line(stronger)
- environment var

Solution:
Write test cases for it

Added two new cases
- for bad str `--port` option
  it produce stdout output that seems unlikely
- for bad `--port` < 0
Problem: 
New functionality - new guide

Solution:
Updated readme on how to boot a `coffer-server`
Problem:
Optparse-applicative wrote err msg directly to stderr which messed up test results msg 

Solution:
Use silently to mute err output
@Kariel-Myrr Kariel-Myrr force-pushed the kariel-myrr/#85-make-the-port-number-configurable branch from 1a509cb to 7d375cd Compare August 7, 2022 11:20
@Kariel-Myrr Kariel-Myrr merged commit 0a61787 into main Aug 7, 2022
@Kariel-Myrr Kariel-Myrr deleted the kariel-myrr/#85-make-the-port-number-configurable branch August 7, 2022 11:29
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.

Make the port number configurable
3 participants