actix-plus-static-files
Legal
Dual-licensed under MIT
or the UNLICENSE.
Overview
- Embed static resources in executable via convenient macro
- Serve static resources as directory in
actix-web
- Support for angular-like routers
- Fork of actix-web-static-files by Alexander Korolev
Usage
Use-case #1: Static resources folder
Create folder with static resources in your project (for example static
):
Add to Cargo.toml
dependency to actix-web-static-files
:
[]
= "0.1.0"
Include static files in Actix Web application:
use ;
use ;
const DIR: Dir = include_dir!;
async
Run the server:
Request the resource:
> GET
> Host:
> User-Agent:
>
< HTTP/1.1
< content-length:
< date:
<
) )
Use-case #2: Angular-like applications
If you are using Angular (or any of a large variety of other such libraries, such as Svelte + Routify) as frontend, you may want to resolve all not found calls via index.html
of frontend app. To do this just call method resolve_not_found_to_root
after resource creation.
use ;
use ;
const DIR: Dir = include_dir!;
async
Remember to place you static resources route after all other routes.