1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

standardize binary names

This commit is contained in:
Rob Ede
2022-02-18 02:22:58 +00:00
parent cfb181ecf5
commit 6f1c9e2350
29 changed files with 10 additions and 10 deletions

View File

@ -0,0 +1,10 @@
[package]
name = "static_index"
version = "1.0.0"
edition = "2021"
[dependencies]
actix-web = "4.0.0-rc.3"
actix-files = "0.6.0-beta.15"
env_logger = "0.9.0"
log = "0.4"

View File

@ -0,0 +1,20 @@
# static_index
Demonstrates how to serve static files. Inside the `./static` folder you will find 2 subfolders:
* `root`: A tree of files that will be served at the web root `/`. This includes the `css` and `js` folders, each
containing an example file.
* `images`: A list of images that will be served at `/images` path, with file listing enabled.
## Usage
```bash
$ cd basics/static_index
$ cargo run
```
### Available Routes
- [GET /](http://localhost:8080/)
- [GET /images](http://localhost:8080/images)

View File

@ -0,0 +1,25 @@
use actix_files::Files;
use actix_web::{middleware::Logger, App, HttpServer};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
log::info!("starting HTTP server at http://localhost:8080");
HttpServer::new(|| {
App::new()
// We allow the visitor to see an index of the images at `/images`.
.service(Files::new("/images", "static/images/").show_files_listing())
// Serve a tree of static files at the web root and specify the index file.
// Note that the root path should always be defined as the last item. The paths are
// resolved in the order they are defined. If this would be placed before the `/images`
// path then the service for the static images would never be reached.
.service(Files::new("/", "./static/root/").index_file("index.html"))
// Enable the logger.
.wrap(Logger::default())
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

@ -0,0 +1,11 @@
body {
text-align: center;
}
h1 {
font-family: sans-serif;
}
img {
transition: .5s ease-in-out;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<meta charset="utf-8" />
<html>
<head>
<link rel="stylesheet" href="css/example.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="/js/example.js"></script>
</head>
<body>
<h1>Actix-web</h1>
<img src="/images/logo.png" alt="Actix logo" />
</body>
</html>

View File

@ -0,0 +1,7 @@
jQuery(document).ready(function () {
let rotation = 0;
jQuery("img").click(function () {
rotation += 360;
jQuery("img").css({'transform': 'rotate(' + rotation + 'deg)'});
});
});