actix server init
This commit is contained in:
parent
abd4299df3
commit
160acb72a2
@ -15,6 +15,10 @@ repository = "https://www.github.com/HsuJv/webgateway"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
actix-web = "3.3.2"
|
||||||
|
actix-files = "0.5.0"
|
||||||
|
tokio-tar = "0.3.0"
|
||||||
|
urlencoding = "2.1.0"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
panic = "unwind"
|
panic = "unwind"
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
[tasks.install]
|
[tasks.install]
|
||||||
|
dependencies = ["build"]
|
||||||
script = '''
|
script = '''
|
||||||
mkdir -p $INSTALL_PATH
|
mkdir -p $INSTALL_PATH
|
||||||
cp $CARGO_MAKE_CRATE_TARGET_DIRECTORY/debug/$CARGO_MAKE_CRATE_NAME $INSTALL_PATH
|
cp $CARGO_MAKE_CRATE_TARGET_DIRECTORY/debug/$CARGO_MAKE_CRATE_NAME $INSTALL_PATH
|
||||||
|
@ -1,3 +1,38 @@
|
|||||||
fn main() {
|
use actix_files as fs;
|
||||||
println!("Hello, world!");
|
use actix_web::http::StatusCode;
|
||||||
|
use actix_web::*;
|
||||||
|
|
||||||
|
const STATIC_DIR: &str = "./static/";
|
||||||
|
// #[get("/{id}/{name}/index.html")]
|
||||||
|
// async fn index(web::Path((id, name)): web::Path<(u32, String)>) -> impl Responder {
|
||||||
|
// format!("Hello {}! id:{}", name, id)
|
||||||
|
// }
|
||||||
|
|
||||||
|
async fn index(_: HttpRequest) -> Result<fs::NamedFile> {
|
||||||
|
Ok(fs::NamedFile::open(format!("{}/index.html", STATIC_DIR))?)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn p404() -> Result<fs::NamedFile> {
|
||||||
|
Ok(fs::NamedFile::open(format!("{}/p404.html", STATIC_DIR))?
|
||||||
|
.set_status_code(StatusCode::NOT_FOUND))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
HttpServer::new(move || {
|
||||||
|
App::new()
|
||||||
|
.service(web::resource("/").route(web::get().to(index)))
|
||||||
|
.service(
|
||||||
|
fs::Files::new("/static", STATIC_DIR)
|
||||||
|
.prefer_utf8(true)
|
||||||
|
.index_file(format!("{}/index.html", STATIC_DIR))
|
||||||
|
.use_etag(true)
|
||||||
|
.default_handler(web::route().to(p404)),
|
||||||
|
)
|
||||||
|
.default_service(web::route().to(p404))
|
||||||
|
})
|
||||||
|
.bind("127.0.0.1:8080")?
|
||||||
|
.run()
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
[tasks.build]
|
[tasks.build]
|
||||||
command = "wasm-pack"
|
command = "wasm-pack"
|
||||||
args = ["build"]
|
args = ["build", "--target", "web", "--out-name", "wasm", "--out-dir", "./pkg", "--dev"]
|
||||||
|
|
||||||
[tasks.install]
|
[tasks.install]
|
||||||
dependencies=["install_wasm", "install_static"]
|
dependencies=["build", "install_wasm", "install_html"]
|
||||||
|
|
||||||
[tasks.install_wasm]
|
[tasks.install_wasm]
|
||||||
script = '''
|
script = '''
|
||||||
mkdir -p $FE_WASM_INSTALL_PATH
|
mkdir -p $FE_STATIC_INSTALL_PATH
|
||||||
cp -r ./pkg $FE_WASM_INSTALL_PATH
|
cp ./pkg/wasm.js $FE_STATIC_INSTALL_PATH
|
||||||
|
cp ./pkg/wasm_bg.wasm $FE_STATIC_INSTALL_PATH
|
||||||
'''
|
'''
|
||||||
|
|
||||||
[tasks.install_static]
|
[tasks.install_html]
|
||||||
script = '''
|
script = '''
|
||||||
mkdir -p $FE_STATIC_INSTALL_PATH
|
mkdir -p $FE_STATIC_INSTALL_PATH
|
||||||
cp www/index.* $FE_STATIC_INSTALL_PATH
|
cp static/* $FE_STATIC_INSTALL_PATH
|
||||||
cp www/bootstrap.js $FE_STATIC_INSTALL_PATH
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
FE_WASM_INSTALL_PATH="${INSTALL_PATH}/html"
|
FE_STATIC_INSTALL_PATH="${INSTALL_PATH}/static"
|
||||||
FE_STATIC_INSTALL_PATH="${INSTALL_PATH}/html/www"
|
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>Hello, World</title>
|
<title>Web Gateway</title>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.navbar {
|
.navbar {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -31,7 +31,12 @@
|
|||||||
height: 58px;
|
height: 58px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script src="./bootstrap.js" defer></script>
|
<script type="module" defer>
|
||||||
|
import init from "/static/wasm.js";
|
||||||
|
import { run_app } from "/static/wasm.js";
|
||||||
|
await init();
|
||||||
|
await run_app();
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
9
frontend/static/p404.html
Normal file
9
frontend/static/p404.html
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<!-- 404 Not found -->
|
||||||
|
<h1>404 Not found</h1>
|
||||||
|
<p>The requested URL was not found on this server.</p>
|
||||||
|
<p>Additionally, a 404 Not Found
|
||||||
|
error was encountered while trying to use an ErrorDocument to handle the request.</p>
|
||||||
|
</body>
|
2
frontend/www/.gitignore
vendored
2
frontend/www/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
node_modules
|
|
||||||
dist
|
|
5
frontend/www/bootstrap.js
vendored
5
frontend/www/bootstrap.js
vendored
@ -1,5 +0,0 @@
|
|||||||
// A dependency graph that contains any wasm must all be imported
|
|
||||||
// asynchronously. This `bootstrap.js` file does the single async import, so
|
|
||||||
// that no one else needs to worry about it again.
|
|
||||||
import("./index.js")
|
|
||||||
.catch(e => console.error("Error importing `index.js`:", e));
|
|
@ -1,5 +0,0 @@
|
|||||||
import { run_app } from '../pkg/webgateway_fe_bg.js';
|
|
||||||
async function main() {
|
|
||||||
run_app();
|
|
||||||
}
|
|
||||||
main()
|
|
11962
frontend/www/package-lock.json
generated
11962
frontend/www/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,32 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "webgateway",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"build": "webpack --config webpack.config.js",
|
|
||||||
"dev": "webpack-dev-server"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/HsuJv/webgateway.git"
|
|
||||||
},
|
|
||||||
"keywords": [
|
|
||||||
"webassembly",
|
|
||||||
"wasm",
|
|
||||||
"rust",
|
|
||||||
"webpack"
|
|
||||||
],
|
|
||||||
"author": "Jovi Hsu <jv.hsu@outlook.com>",
|
|
||||||
"license": "MIT",
|
|
||||||
"homepage": "",
|
|
||||||
"dependencies": {
|
|
||||||
"webgateway": "file:../pkg"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"webpack": "^4.29.3",
|
|
||||||
"webpack-cli": "^3.1.0",
|
|
||||||
"webpack-dev-server": "^3.1.5",
|
|
||||||
"copy-webpack-plugin": "^5.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
entry: "./bootstrap.js",
|
|
||||||
output: {
|
|
||||||
path: path.resolve(__dirname, "dist"),
|
|
||||||
filename: "bootstrap.js",
|
|
||||||
},
|
|
||||||
mode: "development",
|
|
||||||
plugins: [
|
|
||||||
new CopyWebpackPlugin(['index.html'])
|
|
||||||
],
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user