mirror of
https://github.com/actix/examples
synced 2025-06-26 09:17:41 +02:00
refactor: improve basics example
This commit is contained in:
@ -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,
|
||||
)
|
||||
}))
|
||||
|
Reference in New Issue
Block a user