Alles tot aan database, en zaken hernoemd zodat het overeenkomt met boek
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "email_newsletter"
|
name = "zero2prod"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
name = "email_newsletter"
|
name = "zero2prod"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
24
scripts/init_db.sh
Executable file
24
scripts/init_db.sh
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
set -x
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
# Check if a custom user has been set, otherwise default to 'postgress'
|
||||||
|
DB_USER="${POSTGRES_USER:=postgres}"
|
||||||
|
# Check if a custom password has been set, otherwise default to 'password'
|
||||||
|
DB_PASSWORD="${POSTGRES_PASSWORD:=password}"
|
||||||
|
# Check if a custom database name has been set, otherwise default to 'newsletter'
|
||||||
|
DB_NAME="${POSTGRES_DB:=newsletter}"
|
||||||
|
# Check if a custom port has been set, otherwise default to '5432'
|
||||||
|
DB_PORT="${POSTGRES_PORT:=5432}"
|
||||||
|
# Check if a custom host has been set, otherwise default to 'localhost'
|
||||||
|
DB_HOST="${POSTGRES_HOST:=localhost}"
|
||||||
|
|
||||||
|
# Launch postgres using Docker
|
||||||
|
docker run \
|
||||||
|
-e POSTGRES_USER=${DB_USER} \
|
||||||
|
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
|
||||||
|
-e POSTGRES_DB=${DB_NAME} \
|
||||||
|
-p "${DB_PORT}":5432 \
|
||||||
|
-d postgres \
|
||||||
|
postgres -N 1000
|
||||||
|
# ^ Increased maximum number of connections for testing purposes
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::net::TcpListener;
|
use std::net::TcpListener;
|
||||||
|
|
||||||
use email_newsletter::run;
|
use zero2prod::run;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), std::io::Error> {
|
async fn main() -> Result<(), std::io::Error> {
|
||||||
@@ -3,7 +3,7 @@ use std::net::TcpListener;
|
|||||||
fn spawn_app() -> String {
|
fn spawn_app() -> String {
|
||||||
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind to random port");
|
let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind to random port");
|
||||||
let port = listener.local_addr().unwrap().port();
|
let port = listener.local_addr().unwrap().port();
|
||||||
let server = email_newsletter::run(listener).expect("Failed to bind address");
|
let server = zero2prod::run(listener).expect("Failed to bind address");
|
||||||
|
|
||||||
let _ = tokio::spawn(server);
|
let _ = tokio::spawn(server);
|
||||||
|
|
||||||
Reference in New Issue
Block a user