Table of Contents
This repo is a simple project using Vue as the front end and actix as the backend. Meant to be a template or hold examples for your actix projects with a JS frontend. Also JS is used here you can also use this with a rust SPA framework Heavy inspiration from cookiecutter-rust-actix-clean-architecture. This is a "batteries included" template for a lot of things, but falls short in a few places. Especially in the area of Docker hosting with a SSL. So some things may not work as excepted. Feel free to reach out or submit and PRS to improve this template.
Features:
- Example on how actix can host a SPA and resolve to the front end router of the selected framework.
- Uses diesel-async for postgres async queries in diesel.
- A somewhat OOP approach to actix, with trying to not have too much boilerplate.
- Docker compose for self hosting.
- Includes ngix for reverse proxying and hosting ssl.
- Includes postgres for database.
- Includes actix for backend.
- Includes certbot for renewing and creating a ssl.
This is instructions on getting the actix application running, more details on the front end can be found here
- Make a copy of .env.save and name it
.env
, and set your variables.- Note
SESSION_KEY
needs to be a 64 bit key.
- Note
- If you are using docker for the database can run
docker-compose up -d db
to start just the database for development. - Will need to run the diesel migrations to setup the database.
diesel migration run
- If you are not using the included frontend can skip this part.
- Install the front end dependencies
cd vue-project npm install
- To run the front end
npm run build:dev
- Install the front end dependencies
- To run the application
cargo run
- Can check to make sure it's running at http://localhost:8080/api/hello
Below is some lose documentation on setting up the project with docker
-
If you are wanting to use SSL will need to make sure of the following
DOMAIN
is set in the.env
file to the domain you are using.EMAIL
is set in the.env
file to a real email you use.SSL
is set to True in the.env
file to make sure secure cookies are used- Will need the domain pointing to the server running the containers as well as port
80
and443
open. This is the URL lets encrypt will use to verify the domain.
-
Set the contents of default.conf.template to the following. This is to get your initial cert.
server { listen 80 default_server; server_name _; location ~ /.well-known/acme-challenge/ { root /var/www/certbot; } }
-
Run
docker-compose up
to start the containers and cert bot will attempt to get a cert for your domain. -
The certbot container should have gotten the cert. Now need to set the contents of default.conf.template to the following.
# always redirect to https server { listen 80 default_server; server_name _; return 301 https://$host$request_uri; } server { listen 443 ssl http2; ssl_certificate /etc/letsencrypt/live/${DOMAIN}/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/${DOMAIN}/privkey.pem; server_name ${DOMAIN}; root /var/www/html; index index.php index.html index.htm; location / { proxy_pass http://actix-web:8080/; } location ~ /.well-known/acme-challenge/ { root /var/www/certbot; } }
-
Run
docker-compose up
again to restart the containers with the new config and should have it running fully with the SSL!
- Set the contents of default.conf.template to the following.
server { listen 80 default_server; server_name _; location / { proxy_pass http://actix-web:8080/; } }
- I would also comment out the
certbot
service in the docker-compose.yml file. - Run
docker-compose up
to start the containers. - Should be running at http://localhost
- Profit!
- In main.rs:61 can see how the SPA is hosted. Also on line 62 is how I handle allowing the front end router to take over. Anything that would be 404 is sent to the
index.html
- get_user_id.rs is an example of using actix session store in a middleware to set a user id to save todos.
- postgres.rs is an example of using diesel async to set up a connection pool. It is then consumed in todo.rs
Distributed under the MIT License. See LICENSE.txt
for more information.