Skip to content

A simple todo web application using actix-web, PostgreSQL, Svelte, and Halfmoon

Notifications You must be signed in to change notification settings

SL-Lee/actix-web-todo-app

Repository files navigation

actix-web-todo-app

A simple todo web application written using the following technologies/frameworks:

  • actix-web as the backend framework
  • PostgreSQL as the database
  • Svelte as the JavaScript frontend framework
  • Halfmoon as the CSS frontend framework

Setup

Frontend

Before running any of the commands below, make sure you are in the project root.

# Install the dependencies for Svelte
npm install

# Build the JavaScript bundle
npm run build

Database

Before running any of the commands below, make sure you are in the project root.

# Set the `PQ_LIB_DIR` environment variable. See the notes below for more details.
$env:PQ_LIB_DIR = "C:\Program Files\PostgreSQL\14\lib"

# Install the `diesel_cli` binary (if you haven't done so already)
cargo install diesel_cli --no-default-features --features postgres

# Modify the `DATABASE_URL` environment variable accordingly -- once you are done, save the file and close the notepad window.
notepad .\.env

# Run the `diesel setup` command to create the database (if it doesn't exist)
diesel setup

# Run the `diesel migration run` command to create the schema
diesel migration run

Note regarding the PQ_LIB_DIR environment variable:

The PQ_LIB_DIR environment variable is required for compiling pq-sys, a dependency of diesel_cli and the diesel library used by the server. Therefore, this environment variable is required every time you compile the server, so you might want to set it in a more persistent location (e.g. in Windows, set it in the system environment variables).

The code for setting the PQ_LIB_DIR environment variable assumes you have PostgreSQL 14.x installed at the default location on Windows -- if you don't, you'll need to change that line accordingly to point to the location of your PostgreSQL installation's libraries.

As for why setting the PQ_LIB_DIR environment variable is required, here are the relevant links:

Server

Before running any of the commands below, make sure you are in the project root, and the PQ_LIB_DIR environment variable is set.

# Compile the server
cargo build --release

# Download the required library file -- see the notes below for more details.
$baseName = "gettext0.21-iconv1.16-shared-64"
$fileName = "$baseName.zip"
$downloadUrl = "https://github.com/mlocati/gettext-iconv-windows/releases/download/v0.21-v1.16/$fileName"
curl $downloadUrl -o $fileName -L
Expand-Archive $fileName "temp"
Move-Item "temp\bin\libintl-8.dll" "target\release\libintl-9.dll"
Remove-Item "temp", $fileName -Recurse

# Run the server
cargo run --release

Once the server has started successfully, visit http://127.0.0.1:8080/ in your browser (you can customize the server URL by changing the value of the SERVER_URL environment variable in the .env file).

Note regarding the required library:

If you run the server without downloading the required library, running the server will intermittently fail with the exit code 3. The explanation, as well as the solution for this issue, for this can be found here.