Skip to content

Commit b3aa209

Browse files
committed
p21
1 parent 9c369de commit b3aa209

19 files changed

+853
-64
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DATABASE_URL=postgres://postgres:postgres@localhost:5432/test

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Readme.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# rust-wasm
2+
3+
这是一个简单的示例,展示了如何使用 Rust 和 WebAssembly 一起构建 Web 应用程序。
4+
5+
## 安装
6+
7+
你需要安装 Rust 开发工具。你可以通过运行以下命令来完成:
8+
9+
```sh
10+
curl https://sh.rustup.rs -sSf | sh
11+
```
12+
13+
## 运行数据库
14+
15+
```sh
16+
cd db
17+
docker-compose up -d
18+
```
19+
20+
现在你通过 `localhost:5432` 上访问数据库,用户名为 `postgres`,密码为 `postgres`
21+
22+
你还可以在浏览器上访问 `localhost:8081`,用户名为 `postgres`,密码为 `postgres`
23+
24+
## 运行 webservice 和 webapp
25+
26+
首先,你应该设置 `DATABASE_URL` 环境变量,包含数据库凭据,如下所示:`postgres://postgres:postgres@localhost:5432/postgres`
27+
,放在项目根目录的 .env 文件中。
28+
29+
其次,你应该设置 `HOST_PORT` 环境变量,包含主机机器的 IP 地址和端口,如下所示:`http://localhost:8080`,放在 webapp 根目录的
30+
.env 文件中。
31+
32+
要运行 webservice,你可以运行:
33+
34+
```sh
35+
cd webservice
36+
cargo run
37+
```
38+
39+
现在你可以打开另一个终端并运行 webapp。要运行 webapp,你可以运行:
40+
41+
```sh
42+
cd webapp
43+
cargo run
44+
```
45+
46+
## 运行 WebAssembly
47+
48+
要运行 WebAssembly,首先你需要安装 `wasm-pack` 工具:
49+
50+
```sh
51+
cargo install wasm-pack
52+
```
53+
54+
然后,你可以运行以下命令:
55+
56+
```sh
57+
cd wasm-client
58+
wasm-pack build
59+
```
60+
61+
安装 npm 依赖:
62+
63+
```sh
64+
cd wasm-client/www
65+
npm install
66+
```
67+
68+
运行 WebAssembly 应用:
69+
70+
```sh
71+
npm run start
72+
```
73+
74+
## 构建
75+
76+
构建 webservices 和 webapp:
77+
78+
```sh
79+
cargo build --bin teacher-service --release
80+
cargo build --bin svr --release
81+
```
82+
83+
构建 WebAssembly 应用:
84+
85+
```sh
86+
cd wasm-pack
87+
wasm-pack build --release
88+
cd www
89+
npm run build
90+
```

build/dist/0.bootstrap.js

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
199 KB
Binary file not shown.

build/dist/bootstrap.js

Lines changed: 474 additions & 0 deletions
Large diffs are not rendered by default.

build/dist/index.html

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Hello wasm-pack!</title>
7+
<!--引入bootstrap 5-->
8+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
9+
</head>
10+
11+
<body>
12+
<noscript>This page contains webassembly and javascript content, please enable javascript in your browser.</noscript>
13+
<nav class="navbar navbar-dark bg-primary">
14+
<div class="container-fluid">
15+
<a class="navbar-brand" href="#">Wasm-client</a>
16+
</div>
17+
</nav>
18+
<div class="m-3" style="height: 600px">
19+
<div class="row">
20+
<div class="col">
21+
<div class="card border-info mb-3">
22+
<div class="card-header">Course</div>
23+
<div class="card-body">
24+
<button type="button" class="btn btn-primary">Add</button>
25+
</div>
26+
<table class="table table-hover table-bordered table-sm">
27+
<thead>
28+
<tr>
29+
<th scope="col">ID</th>
30+
<th scope="col">Name</th>
31+
<th scope="col">Time</th>
32+
<th scope="col">Description</th>
33+
<th scope="col">Option</th>
34+
</tr>
35+
</thead>
36+
<tbody id="left-tbody"></tbody>
37+
</table>
38+
</div>
39+
</div>
40+
<div class="col">
41+
<div class="card border-info mb-3">
42+
<div class="card-header">Add Course</div>
43+
<div class="card-body">
44+
<form class="row g-3 needs-validation" id="form">
45+
<div class="mb-3">
46+
<label for="name" class="form-label">Course Name</label>
47+
<input type="text" class="form-control" id="name" required placeholder="Please fill in Course name">
48+
<div class="invalid-feedback">Please fill in course name</div>
49+
</div>
50+
<div class="mb-3">
51+
<label for="description" class="form-label">Description</label>
52+
<textarea class="form-control" id="description" rows="3"
53+
placeholder="Please fill in description"></textarea>
54+
</div>
55+
<div class="col-12">
56+
<button type="submit" class="btn btn-primary">Submit</button>
57+
</div>
58+
</form>
59+
</div>
60+
</div>
61+
</div>
62+
</div>
63+
</div>
64+
<script src="./bootstrap.js"></script>
65+
</body>
66+
67+
</html>

build/svr

11.1 MB
Binary file not shown.

build/teacher-service

9 MB
Binary file not shown.

db/db.sql

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)