Skip to content

Check if an email address exists without sending any email, written in Rust. Comes with a ⚙️ HTTP backend.

fix: Allow http to listen to $PORT env variable (#215)

Amaury Martiny3b0c262763bc
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 86627d37..4f6b408d 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -87,8 +87,10 @@ jobs:
# https://github.com/olegtarasov/get-tag
- uses: olegtarasov/get-tag@v2
- - name: Package
- run: tar czf $CRATE_NAME-$GIT_TAG_NAME-$TARGET.tar.gz target/$TARGET/release/$BIN_NAME
+ - name: Package into tar/zip
+ run: |
+ cp target/$TARGET/release/$BIN_NAME .
+ tar czf $CRATE_NAME-$GIT_TAG_NAME-$TARGET.tar.gz $BIN_NAME
# https://github.com/actions/create-release/issues/14#issuecomment-555379810
- name: Load Release URL File from release job
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 26c0585b..5e2bff81 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,10 +2,6 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
-### [0.6.3](https://github.com/amaurymartiny/check_if_email_exists/compare/v0.6.2...v0.6.3) (2020-02-28)
-
-### [0.6.2](https://github.com/amaurymartiny/check_if_email_exists/compare/v0.6.1...v0.6.2) (2020-02-28)
-
### [0.6.1](https://github.com/amaurymartiny/check_if_email_exists/compare/v0.6.0...v0.6.1) (2020-02-18)
diff --git a/src/cli.yml b/src/cli.yml
index de3da940..8f0cf29e 100644
--- a/src/cli.yml
+++ b/src/cli.yml
@@ -1,28 +1,26 @@
name: check_if_email_exists
-version: "0.6.1"
author: Amaury Martiny <[email protected]>
about: Check if an email address exists without sending any email.
args:
- FROM_EMAIL:
default_value: [email protected]
long: from
- help: The from email to use in the SMTP connection
+ help: The from email to use in the SMTP connection.
takes_value: true
- HTTP:
long: http
- help: Runs a HTTP server
+ help: Runs a HTTP server.
- HTTP_HOST:
default_value: "127.0.0.1"
long: http-host
- help: Sets the host IP address on which the HTTP server should bind. Only used when `--http` flag is on
+ help: Sets the host IP address on which the HTTP server should bind. Only used when `--http` flag is on.
takes_value: true
value_name: HOST
- HTTP_PORT:
- default_value: "3000"
long: http-port
- help: Sets the port on which the HTTP server should bind. Only used when `--http` flag is on
+ help: Sets the port on which the HTTP server should bind. Only used when `--http` flag is on. If not set, then it will use $PORT, or default to 3000.
takes_value: true
value_name: PORT
- TO_EMAIL:
- help: The email to check
+ help: The email to check.
index: 1
diff --git a/src/main.rs b/src/main.rs
index 8f3475c0..f1d3b684 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -24,8 +24,9 @@ extern crate tokio;
mod http;
use check_if_email_exists::email_exists;
-use clap::App;
+use clap::{crate_version, App};
use serde_json;
+use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
@@ -33,7 +34,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// The YAML file is found relative to the current file, similar to how modules are found
let yaml = clap::load_yaml!("cli.yml");
- let matches = App::from_yaml(yaml).get_matches();
+ let matches = App::from_yaml(yaml).version(crate_version!()).get_matches();
if let Some(to_email) = matches.value_of("TO_EMAIL") {
let from_email = matches
@@ -57,9 +58,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let http_host = matches
.value_of("HTTP_HOST")
.expect("HTTP_HOST has a default value. qed.");
- let http_port = matches
- .value_of("HTTP_PORT")
- .expect("HTTP_PORT has a default value. qed.");
+ // http_port is, in this order:
+ // - the value of `--http-port` flag
+ // - if not set, then the $PORT env varialbe
+ // - if not set, then 3000
+ let env_port = env::var("PORT").unwrap_or_else(|_| "3000".into());
+ let http_port = matches.value_of("HTTP_PORT").unwrap_or(&env_port);
http::run(http_host, http_port.parse::<u16>().unwrap()).await?
}