generated from lucien/actix-react-template
Merged back_end to main branch #5
2 changed files with 25 additions and 2 deletions
|
@ -6,4 +6,6 @@ edition = "2021"
|
|||
[dependencies]
|
||||
actix-files = "0.6.6"
|
||||
actix-web = "4"
|
||||
serde = "1.0.215"
|
||||
serde_json = "1.0.133"
|
||||
|
||||
|
|
|
@ -1,11 +1,32 @@
|
|||
use actix_web::{App, HttpServer};
|
||||
use actix_web::{App, HttpServer, get, Responder, HttpResponse, http::header::ContentType};
|
||||
use actix_files::Files;
|
||||
use serde_json::json;
|
||||
|
||||
|
||||
#[get("/api")]
|
||||
async fn api() -> impl Responder {
|
||||
let value = json!({
|
||||
"code": 200,
|
||||
"success": true,
|
||||
"payload": {
|
||||
"features": [
|
||||
"serde",
|
||||
"json"
|
||||
],
|
||||
"homepage": null
|
||||
}
|
||||
});
|
||||
HttpResponse::Ok()
|
||||
.content_type(ContentType::json())
|
||||
.body(value.to_string())
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.service(Files::new("/", "./public").index_file("index.html"))
|
||||
.service(api)
|
||||
.service(Files::new("/", "public").index_file("index.html"))
|
||||
})
|
||||
.bind(("0.0.0.0", 8080))?
|
||||
.run()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue