blob: 89ddc26a01986f58e18c66f035d660294823bd06 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# Gradecoin
This is designed to sit behind nginx reverse proxy so running at 127.0.0.1:8080 or not using https is not a problem.
It's currently live over at https://gradecoin.xyz.
```sh
# Test the project
$ cargo test
# Read the documentation
$ cargo doc --open
```
The executable `main` needs the `/templates`, `users` and `blocks` folders. It also expects a `secrets/gradecoin.pem` file with the private key of the system.
# Running Locally
Create RSA keys:
```sh
$ mkdir secrets
$ cd secrets
$ openssl genrsa -out gradecoin.pem 2048
$ openssl rsa -in gradecoin.pem -outform PEM -pubout -out gradecoin.pub
```
Use `gradecoin.pub` file in your client program.
Create students list: `students.csv` should be in the following form:
```
User ID, Password
e123456,register_password
e123456,register_password
```
First line is ignored.
Run the server:
```sh
$ cargo run
```
The server should be up on `localhost:8080`.
The default config file is `config.yaml`.
You can specify another config file with:
```sh
$ cargo run another_config.yaml
```
You can even run multiple networks at once by giving multiple configuration files:
```sh
# Run both the main network (at /) and testnet (at /testnet)
# For example, register for main network at `localhost:8080/register`,
# testnet network at `localhost:8080/testnet/register`
$ cargo run config.yaml testnet.yaml
```
In the config file, `url_prefix` field determines the address of the network.
You can clear the database for all networks by running:
```sh
$ rm -rf blocks users
```
Or you can delete the database for a particular network by removing `blocks/network_name` and `users/network_name`.
# References
- https://github.com/blurbyte/restful-rust
- https://github.com/zupzup/warp-postgres-example
- https://blog.logrocket.com/create-an-async-crud-web-service-in-rust-with-warp/
# How to be a good server
- https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
- https://tools.ietf.org/html/rfc7231
|