thruster-rs / Thruster

A fast, middleware based, web framework written in Rust
MIT License
1.07k stars 47 forks source link

index route #73

Closed AlbanMinassian closed 6 years ago

AlbanMinassian commented 6 years ago

app.get("/", vec![index]); not recognize !

How catch index page ? Ami44

most_basic.rs:

extern crate thruster;
extern crate futures;

use std::boxed::Box;
use futures::future;

use thruster::{App, BasicContext as Ctx, MiddlewareChain, MiddlewareReturnValue};

fn index(mut context: Ctx, _chain: &MiddlewareChain<Ctx>) -> MiddlewareReturnValue<Ctx> {
  context.body = "Hello, Index!".to_owned();;
  Box::new(future::ok(context))
}
fn plaintext(mut context: Ctx, _chain: &MiddlewareChain<Ctx>) -> MiddlewareReturnValue<Ctx> {
  context.body = "Hello, Plaintext !".to_owned();;
  Box::new(future::ok(context))
}

fn page404(mut context: Ctx, _chain: &MiddlewareChain<Ctx>) -> MiddlewareReturnValue<Ctx> {
  context.body = "Hello, 404 !".to_owned();;
  Box::new(future::ok(context))
}

fn main() {
  println!("Starting server...");

  let mut app = App::<Ctx>::new();

  app.get("/", vec![index]);
  app.get("/plaintext", vec![plaintext]);
  app.get("/*", vec![page404]);

  App::start(app, "0.0.0.0", 4321);
}
AlbanMinassian commented 6 years ago

Hello, can you merge on master ?

AlbanMinassian commented 6 years ago

Thank, it's work