Skip to content

Commit 926ede5

Browse files
committed
merge multi_config
It's a big commit! - fix: npm package error - fix: wrong check when release new domain - feat: support multiple config for different domain - feat: support multiple ssl - doc: add multile config doc - doc: add break change doc
1 parent 7b48514 commit 926ede5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+5159
-491
lines changed

.github/workflows/spa-client-js-cd.yml

Lines changed: 392 additions & 50 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
/tmp
44
config.conf
55
/node_modules
6-
package-lock.json
6+
package-lock.json
7+
8+
.DS_Store

Cargo.lock

Lines changed: 67 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ It is to provide a static web http server with cache and hot reload.
1313
- Http auto redirect to https.
1414
- Docker support(compressed size: 32M).
1515
- Provide command line/npm package to deploy spa.
16+
- Multiple configs for different domain.
1617

1718
## Document
1819
There is a nice [document](https://timzaak.github.io/spa-server/) powered by VitePress and GitHub Pages,

README_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- http/https 同时服务(http 也可返回 redirect https)。
1313
- 支持 Docker 镜像(压缩后大小:32M)
1414
- 提供 命令行/npm包 客户端,一行命令部署
15+
- 每个域名可拥有独立的配置
1516

1617
## 文档
1718
目前将文档托管在 GitHub Pages,地址:https://timzaak.github.io/spa-server,

client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ indicatif = "0.16"
4646

4747
md-5 = "0.10"
4848
# util
49-
anyhow = "1.0"
49+
anyhow = { version = "1.0", features = ["backtrace"] }
5050
walkdir = "2.3"
5151
if_chain = "1.0"
5252

client/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::api::API;
1010
use crate::commands::{CliCommand, Commands};
1111
use crate::config::Config;
1212
use crate::upload_files::upload_files;
13-
use anyhow::{anyhow, Context};
13+
use anyhow::anyhow;
1414

1515
use clap::Parser;
1616
use console::style;
@@ -42,10 +42,10 @@ fn success(message: &str) {
4242

4343
fn run_with_commands(commands: CliCommand) -> anyhow::Result<()> {
4444
let config = Config::load(commands.config_dir).map_err(|e| {
45-
Err(anyhow!(
45+
anyhow!(
4646
"Please set config file path or environment variable correctly, {}",
4747
e
48-
));
48+
)
4949
})?;
5050
println!(
5151
"spa-client connect to admin server({})",
@@ -108,11 +108,11 @@ mod test {
108108
#[test]
109109
fn test_release() {
110110
init_config();
111-
run_with_commands(CliCommand::parse_from(&[
111+
let result = run_with_commands(CliCommand::parse_from(&[
112112
"test",
113113
"release",
114114
"self.noti.link",
115-
]))
116-
.unwrap();
115+
]));
116+
result.unwrap();
117117
}
118118
}

config.release.conf

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,47 @@
1-
# http bind, if set port <= 0, will disable http server.
1+
# http bind, if set port <= 0, will disable http server(need set https config)
22
port = 80
33
addr = "0.0.0.0"
44

5-
# directory to store static files.
5+
# directory to store static web files. if you use docker, please mount a persistence volume for it.
66
file_dir = "/data"
77

88
# enable cors, default is false, its implementation is simple now.
9-
# Access-Control-Allow-Origin: *
9+
# Access-Control-Allow-Origin: $ORIGIN
1010
# Access-Control-Allow-Methods: OPTION,GET,HEAD
1111
# Access-Control-Max-Age: 3600
1212
// cors = true
1313

1414
# https config, optional
1515
//https {
16-
// # private ssl key
17-
// private = "private.key path",
18-
// # public ssl cert
19-
// public = "public.cert path"
16+
// # default value for https ssl
17+
// ssl {
18+
// # private ssl key
19+
// private = "private.key path",
20+
// # public ssl cert
21+
// public = "public.cert path"
22+
// }
23+
24+
// # https bind address
2025
// port = 443
2126
// addr = "0.0.0.0"
22-
// # if set true, http server(80) will send client 301(Moved Permanently) to https.
27+
28+
// # if set true, http server(80) will send client
29+
// # status code:301(Moved Permanently) to tell client redirect to https
2330
// # optional, default is false
2431
// http_redirect_to_https = false
25-
// # gzip compression for js/json/icon/json, default is false,
26-
// # only support gzip algo, only compress cached files,
27-
// # will occur error when client don't support gzip
28-
// # be careful to set it true
29-
// compression = false
3032
//}
3133

32-
# cache config
34+
35+
36+
# default cache config
3337
//cache {
3438
// # if file size > max_size, it will not be cached. default is 10485760 (10MB).
35-
// # do not use size unit format like 50m! It's blocked by [hocon #62](https://github.com/mockersf/hocon.rs/issues/62)
39+
// # do not use size unit format like 50MB!
40+
// # It's blocked by [hocon #62](https://github.com/mockersf/hocon.rs/issues/62)
3641
// max_size = 10485760 //10MB 10*1024*1024
37-
// # Cache-Control config, optional
42+
43+
// # http header Cache-Control config,
44+
// # optional, if not set, won't sender this header to client
3845
// client_cache = [{
3946
// expire = 30d
4047
// extension_names = [icon,gif,jpg,jpeg,png,js]
@@ -43,14 +50,48 @@ file_dir = "/data"
4350
// expire = 0
4451
// extension_names = [html]
4552
// }]
53+
54+
// # gzip compression for js/json/icon/json, default is false,
55+
// # only support gzip algo, and only compress cached files,
56+
// # be careful to set it true
57+
// compression = false
58+
4659
//}
4760

48-
# admin server config, optional, and it's disabled by default. hot reload don't support admin server reload. the config should not change.
61+
//# admin server config
62+
//# admin server don't support hot reload. the config should not change.
63+
//# optional, and it's disabled by default.
64+
//# if you use spa-client to upload files, control version. Need to open it
4965
//admin_config {
66+
//# bind host
5067
// port = 9000
5168
// addr = "127.0.0.1"
52-
// # this is used as auth check. In Header: Authorization: Bearer token
69+
70+
// # this is used to check client request
71+
// # put it in http header, Authorization: Bearer $token
5372
// token = "token"
54-
// # max file size allowed to be uploaded, default is 30MB(30*1024*1024)
73+
74+
// # max file size allowed to be uploaded,
75+
// # default is 30MB(30*1024*1024)
5576
// max_upload_size = 31457280
5677
//}
78+
79+
80+
# optional, domains specfic config, it will use the default config if not set
81+
//domains = [{
82+
// # domain name
83+
// domain: "www.example.com",
84+
// // optional, same with cache config, if not set, will use default cache config.
85+
// cache: {
86+
// client_cache:${cache.client_cache}
87+
// max_size: ${cache.max_size}
88+
// client_cache = ${cache.client_cache}
89+
// },
90+
// # cors
91+
// cors: ${cors},
92+
// # domain https config, if not set, will use default https config.
93+
// https: {
94+
// ssl: ${https.ssl}
95+
// http_redirect_to_https: ${https.http_redirect_to_https}
96+
// }
97+
//}]

docs/config.md

Whitespace-only changes.

docs/develop/develop-tips.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ VERSION=1.2.1
77

88
DOCKER_BUILDKIT=1 docker build . -t="timzaak/spa-server:$VERSION"
99

10-
```
10+
```
11+
12+
## SSL self sign
13+
you can go here to sign: http://cookcode.cc/selfsign

0 commit comments

Comments
 (0)