mirror of
https://github.com/actix/examples
synced 2025-06-06 09:28:06 +02:00
refactor: improve basics example
This commit is contained in:
parent
92b0688df6
commit
03da1cb967
26
Cargo.lock
generated
26
Cargo.lock
generated
@ -1705,19 +1705,6 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "basics"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"actix-files",
|
||||
"actix-session",
|
||||
"actix-web",
|
||||
"actix-web-lab",
|
||||
"async-stream",
|
||||
"env_logger",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bb8"
|
||||
version = "0.8.6"
|
||||
@ -3142,6 +3129,19 @@ version = "2.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
|
||||
|
||||
[[package]]
|
||||
name = "example-basics"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"actix-files",
|
||||
"actix-session",
|
||||
"actix-web",
|
||||
"actix-web-lab",
|
||||
"async-stream",
|
||||
"examples-common",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "example-cert-watch"
|
||||
version = "0.0.0"
|
||||
|
@ -98,6 +98,7 @@ actix-web-lab = "0.24"
|
||||
actix-ws = "0.3"
|
||||
awc = "3.7"
|
||||
|
||||
async-stream = "0.3"
|
||||
chrono = { version = "0.4.30", features = ["serde"] }
|
||||
color-eyre = "0.6"
|
||||
derive_more = "2"
|
||||
|
@ -1,14 +1,13 @@
|
||||
[package]
|
||||
name = "basics"
|
||||
name = "example-basics"
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
actix-files.workspace = true
|
||||
actix-files = { workspace = true }
|
||||
actix-session = { workspace = true, features = ["cookie-session"] }
|
||||
actix-web.workspace = true
|
||||
actix-web-lab.workspace = true
|
||||
|
||||
async-stream = "0.3"
|
||||
env_logger.workspace = true
|
||||
log.workspace = true
|
||||
actix-web = { workspace = true }
|
||||
actix-web-lab = { workspace = true }
|
||||
async-stream = { workspace = true }
|
||||
examples-common = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
|
@ -1,8 +1,8 @@
|
||||
# basics
|
||||
# Basics
|
||||
|
||||
## Usage
|
||||
|
||||
### server
|
||||
### Server
|
||||
|
||||
```sh
|
||||
cd basics/basics
|
||||
@ -10,7 +10,7 @@ cargo run
|
||||
# Started http server: 127.0.0.1:8080
|
||||
```
|
||||
|
||||
### web client
|
||||
### Browser
|
||||
|
||||
- [http://localhost:8080/async-body/bob](http://localhost:8080/async-body/bob)
|
||||
- [http://localhost:8080/user/bob/](http://localhost:8080/user/bob) text/plain download
|
||||
|
@ -78,12 +78,12 @@ async fn with_param(req: HttpRequest, Path((name,)): Path<(String,)>) -> HttpRes
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
examples_common::init_standard_logger();
|
||||
|
||||
// random key means that restarting server will invalidate existing session cookies
|
||||
let key = actix_web::cookie::Key::from(SESSION_SIGNING_KEY);
|
||||
|
||||
log::info!("starting HTTP server at http://localhost:8080");
|
||||
tracing::info!("Starting HTTP server at http://localhost:8080");
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
@ -96,7 +96,7 @@ async fn main() -> io::Result<()> {
|
||||
.build(),
|
||||
)
|
||||
// enable logger - always register Actix Web Logger middleware last
|
||||
.wrap(middleware::Logger::default())
|
||||
.wrap(middleware::Logger::default().log_target("@"))
|
||||
// register favicon
|
||||
.service(favicon)
|
||||
// register simple route, handle all methods
|
||||
@ -114,7 +114,7 @@ async fn main() -> io::Result<()> {
|
||||
)
|
||||
.service(web::resource("/error").to(|| async {
|
||||
error::InternalError::new(
|
||||
io::Error::new(io::ErrorKind::Other, "test"),
|
||||
io::Error::other("test"),
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
}))
|
||||
|
@ -9,7 +9,7 @@ pub fn init_standard_logger() {
|
||||
.with_default_directive(LevelFilter::INFO.into())
|
||||
.from_env_lossy(),
|
||||
)
|
||||
.with(tracing_subscriber::fmt::layer())
|
||||
.with(tracing_subscriber::fmt::layer().without_time())
|
||||
.init();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user