"Before starting, please use cargo test
to create the relevant tables."
#[cfg(test)] mod usertable { use super::*; #[test] fn test_create_user_table() { create_user_table(); } }
run
cargo test
cargo run
We put self-signed certificate in this directory as an example but your browser will complain that connections to the server aren't secure. We recommend to use mkcert
to trust it. To use a local CA, you should run:
mkcert -install
If you want to generate your own private key/certificate pair, then run:
mkcert -key-file key.pem -cert-file cert.pem 127.0.0.1 localhost
A new key.pem
and cert.pem
will be saved to the current directory. You will then need to modify main.rs
where indicated.
-
clone vcpkg
-
open directory where you've cloned vcpkg
-
run
./bootstrap-vcpkg.bat
-
run
./vcpkg.exe install openssl-windows:x64-windows
-
run
./vcpkg.exe install openssl:x64-windows-static
-
run
./vcpkg.exe integrate install
-
run
set VCPKGRS_DYNAMIC=1
(or simply set it as your environment variable) -
Add environment variables
$env:OPENSSL_DIR="<vcpkg>\installed\x64-windows-static"
-
Ensure that the environment variables already exist in the terminal:powershell run
$env:OPENSSL_DIR
PS D:\...\actix-web-authDemo> $env:OPENSSL_DIR D:\installed\vcpkg\installed\x64-windows-static
-
Install
pkg-config
: You need to installpkg-config
on your Linux distribution. Depending on your operating system, the installation command might vary: For Ubuntu/Debian:sudo apt install pkg-config
For Fedora:sudo dnf install pkg-config
For CentOS/RedHat:sudo yum install pkg-config
For Alpine Linux:sudo apk add pkgconfig
-
Install OpenSSL Development Package: You also need to make sure that the development package of
OpenSSL
is installed: For Ubuntu/Debian:sudo apt install libssl-dev
For Fedora:sudo dnf install openssl-devel
For CentOS/RedHat:sudo yum install openssl-devel
For Alpine Linux:sudo apk add openssl-dev
-
Set Environment Variable (if necessary): If you still encounter issues after installing the above packages, you might need to set the OPENSSL_DIR environment variable to help the openssl-sys crate locate the OpenSSL installation.
update main.js
#[actix_web::main] async fn main() -> std::io::Result<()> { // configure openssl let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap(); builder .set_private_key_file("cert/key.pem", SslFiletype::PEM) .unwrap(); builder.set_certificate_chain_file("cert/cert.pem").unwrap(); env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); HttpServer::new(|| { App::new() ... ... }) .bind_openssl("127.0.0.1:8080",builder)? // .bind("127.0.0.1:8080")? .workers(1) .run() .await }
cargo run