#svelte #website #ease #localhost #plugin #http #query

expressrs

轻松在本地主机上创建网站!

5 个版本

0.1.6 2024 年 7 月 6 日
0.1.5 2024 年 7 月 5 日

#884 in 网络编程

Download history 205/week @ 2024-06-28 342/week @ 2024-07-05 15/week @ 2024-07-12

每月 230 次下载
用于 svelte-parser

AGPL-1.0-only

26KB
568

ExpressRS

轻松制作 HTTP 本地主机!

想法

变更日志

  • 插件支持
  • 查询参数解析
  • URL 解码

示例

// main.rs

use expressrs::ExpressLib;

fn main() {
    let express = ExpressLib::new();
    let mut app = express();

    // Create a directory called public/ that has index.html and script.js
    app.serve_directory("public");

    app.get("/", |_, res| {
        res.status(200).send_file("public/index.html");
    });

    app.listen(3030, |port| {
        println!("Server listening at https://127.0.0.1:{}", port);
    });
}

查询参数示例

// main.rs

use expressrs::ExpressLib;

fn main() {
    let express = ExpressLib::new();
    let mut app = express();

	// This will replace the response IF the query parameter is not found
    app.get("/:user", |_, res| {
		// IS required to be Some() (aka Something)
        println!("{:?}", req.queries.get("user"));
		// Can be None unless it is added to the query parameters
        println!("{:?}", req.queries.get("database"));
    });

    app.listen(3030, |port| {
        println!("Server listening at https://127.0.0.1:{}", port);
    });
}

依赖项

serde_json 1.0

serde { features = ["derive"], version = "1.0" }

依赖项

~0.7–1.6MB
~35K SLoC