Skip to content

Commit 71f41a8

Browse files
committed
bak
1 parent 1bf4e96 commit 71f41a8

6 files changed

Lines changed: 6 additions & 116 deletions

File tree

‎config.release.toml‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
11
## directory to store static web files. if you use docker, please mount a persistence volume for it.
22
file_dir = "/data"
33

4-
## enable cors, default is none, if cors is [], then all cors is ok.
5-
## Access-Control-Allow-Origin: $ORIGIN
6-
## Access-Control-Allow-Methods: OPTION,GET,HEAD
7-
## Access-Control-Max-Age: 3600
8-
## If you put the server behind HTTPS proxy, please enable it, or domains.cors = ['http://www.example.com:8080']
9-
## Attension: domains.cors config would overwrite the cors config, rather than merge this.
10-
cors = []
114
## http bind, if set port <= 0 or remove http, will disable http server(need set https config)
125
[http]
136
port = 80
147
addr = "0.0.0.0"
15-
## port when serving public network,default is http port. external_port should not be 0.
16-
# external_port = 80
17-
18-
## optional, when https enabled, redirect_https default value true
19-
## it would the port would be https.external_port(https.external_port should be defined), otherwise is false
20-
# redirect_https = true
21-
228

239
## admin server config
2410
## admin server don't support hot reload. the config should not change.
@@ -46,8 +32,3 @@ addr = "0.0.0.0"
4632
# domain = "www.example.com"
4733
## optional, `example.com` would redirect to `www.example.com`
4834
# alias = ["example.com"]
49-
# cors = ['https://www.example.com', 'http://www.baidu.com']
50-
# [domains.https]
51-
## optional, when https enabled, redirect_https default value true
52-
## it would the port would be https.external_port(https.external_port should be defined), otherwise is false
53-
# redirect_https = 443

‎config.toml‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
## directory to store static web files. if you use docker, please mount a persistence volume for it.
22
file_dir = "./data"
33

4-
## enable cors, default is none, if cors is [], then all cors is ok.
5-
## Access-Control-Allow-Origin: $ORIGIN
6-
## Access-Control-Allow-Methods: OPTION,GET,HEAD
7-
## Access-Control-Max-Age: 3600
8-
## If you put the server behind HTTPS proxy, please enable it, or domains.cors = ['http://www.example.com:8080']
9-
## Attension: domains.cors config would overwrite the cors config, rather than merge this.
10-
cors = []
4+
115
## http bind, if set port <= 0 or remove http, will disable http server(need set https config)
126
[http]
137
port = 80
148
addr = "0.0.0.0"
15-
## port when serving public network,default is http port. external_port should not be 0.
16-
# external_port = 80
17-
18-
## optional, when https enabled, redirect_https default value true
19-
## it would the port would be https.external_port(https.external_port should be defined), otherwise is false
20-
# redirect_https = true
219

2210
## admin server config
2311
## admin server don't support hot reload. the config should not change.
@@ -45,8 +33,3 @@ addr = "0.0.0.0"
4533
# domain = "www.example.com"
4634
## optional, `example.com` would redirect to `www.example.com`
4735
# alias = ["example.com"]
48-
# cors = ['https://www.example.com', 'http://www.baidu.com']
49-
# [domains.https]
50-
## optional, when https enabled, redirect_https default value true
51-
## it would the port would be https.external_port(https.external_port should be defined), otherwise is false
52-
# redirect_https = 443

‎docs/guide/spa-server-configuration.md‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,12 @@ The config default path is `./config.toml`, you can change it by environment `SP
1212

1313
```toml
1414
## directory to store static web files. if you use docker, please mount a persistence volume for it.
15-
file_dir = "./data"
15+
file_dir = "/data"
1616

17-
## enable cors, default is none, if cors is [], then all cors is ok.
18-
## Access-Control-Allow-Origin: $ORIGIN
19-
## Access-Control-Allow-Methods: OPTION,GET,HEAD
20-
## Access-Control-Max-Age: 3600
21-
## If you put the server behind HTTPS proxy, please enable it, or domains.cors = ['http://www.example.com:8080']
22-
## Attension: domains.cors config would overwrite the cors config, rather than merge this.
23-
cors = []
2417
## http bind, if set port <= 0 or remove http, will disable http server(need set https config)
2518
[http]
2619
port = 80
2720
addr = "0.0.0.0"
28-
## port when serving public network,default is http port. external_port should not be 0.
29-
# external_port = 80
30-
31-
## optional, when https enabled, redirect_https default value true
32-
## it would the port would be https.external_port(https.external_port should be defined), otherwise is false
33-
# redirect_https = true
3421

3522
## admin server config
3623
## admin server don't support hot reload. the config should not change.
@@ -58,10 +45,5 @@ addr = "0.0.0.0"
5845
# domain = "www.example.com"
5946
## optional, `example.com` would redirect to `www.example.com`
6047
# alias = ["example.com"]
61-
# cors = ['https://www.example.com', 'http://www.baidu.com']
62-
# [domains.https]
63-
## optional, when https enabled, redirect_https default value true
64-
## it would the port would be https.external_port(https.external_port should be defined), otherwise is false
65-
# redirect_https = 443
6648

6749
```

‎jsclient/test/config.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
file_dir = "./data"
2-
cors = true # would change
2+
cors = []
33
[http]
44
port = 8080
55
addr = "0.0.0.0"

‎server/src/config.rs‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
use anyhow::{Context, bail};
2-
use duration_str::deserialize_duration;
32
use salvo::http::HeaderValue;
43
use serde::{Deserialize, Deserializer};
5-
use std::collections::HashSet;
6-
use std::time::Duration;
74
use std::{env, fs};
85

96
const CONFIG_PATH: &str = "config.toml";
107

118
#[derive(Deserialize, Debug, Clone, PartialEq)]
129
pub struct Config {
1310
pub file_dir: String,
14-
#[serde(default)]
15-
pub cors: Option<HashSet<OriginWrapper>>,
1611
pub admin_config: Option<AdminConfig>,
1712
pub http: HttpConfig,
1813
#[serde(default)]
@@ -60,38 +55,13 @@ fn default_max_upload_size() -> u64 {
6055
#[derive(Deserialize, Debug, Clone, PartialEq)]
6156
pub struct DomainConfig {
6257
pub domain: String,
63-
pub cors: Option<HashSet<OriginWrapper>>,
64-
pub https: Option<DomainHttpsConfig>,
6558
pub alias: Option<Vec<String>>,
66-
pub redirect_https: Option<bool>,
67-
}
68-
69-
#[derive(Deserialize, Debug, Clone, PartialEq)]
70-
pub struct DomainHttpsConfig {
71-
pub ssl: Option<SSL>,
72-
#[serde(default)]
73-
pub disable_acme: bool,
74-
}
75-
76-
#[derive(Deserialize, Debug, Clone, PartialEq)]
77-
pub struct SSL {
78-
pub private: String,
79-
pub public: String,
8059
}
8160

8261
#[derive(Deserialize, Debug, Clone, PartialEq)]
8362
pub struct HttpConfig {
8463
pub addr: String,
8564
pub port: u16,
86-
pub external_port: Option<u16>,
87-
pub redirect_https: Option<bool>,
88-
}
89-
90-
#[derive(Deserialize, Debug, Clone, PartialEq)]
91-
pub struct ClientCacheItem {
92-
#[serde(deserialize_with = "deserialize_duration")]
93-
pub expire: Duration,
94-
pub extension_names: Vec<String>,
9565
}
9666

9767
#[derive(Deserialize, Debug, Clone, Eq, PartialEq)]
@@ -118,13 +88,6 @@ pub fn get_host_path_from_domain(domain: &str) -> (&str, &str) {
11888
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11989
pub struct OriginWrapper(HeaderValue);
12090

121-
pub(crate) fn extract_origin(
122-
data: &Option<HashSet<OriginWrapper>>,
123-
) -> Option<HashSet<HeaderValue>> {
124-
data.as_ref()
125-
.map(|set| set.iter().map(|o| o.0.clone()).collect())
126-
}
127-
12891
impl<'de> Deserialize<'de> for OriginWrapper {
12992
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
13093
where

‎server/src/service.rs‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
use crate::config::{Config, extract_origin};
1+
use crate::config::Config;
22
use salvo::Response;
3-
use salvo::http::{HeaderValue, StatusCode};
4-
use std::collections::{HashMap, HashSet};
3+
use salvo::http::StatusCode;
4+
use std::collections::HashMap;
55
use std::sync::Arc;
66

77
pub struct ServiceConfig {
8-
pub default: DomainServiceConfig,
9-
pub inner: HashMap<String, DomainServiceConfig>,
108
pub host_alias: Arc<HashMap<String, String>>,
119
}
1210

13-
pub struct DomainServiceConfig {
14-
pub cors: Option<HashSet<HeaderValue>>,
15-
}
16-
1711
impl ServiceConfig {
1812
/*
1913
fn get_domain_service_config(&self, domain: &str) -> &DomainServiceConfig {
@@ -22,17 +16,6 @@ impl ServiceConfig {
2216
2317
*/
2418
pub fn new(conf: &Config) -> Self {
25-
let default = DomainServiceConfig {
26-
cors: extract_origin(&conf.cors),
27-
};
28-
let mut service_config: HashMap<String, DomainServiceConfig> = HashMap::new();
29-
for domain in conf.domains.iter() {
30-
let domain_service_config: DomainServiceConfig = DomainServiceConfig {
31-
cors: extract_origin(&domain.cors).or_else(|| default.cors.clone()),
32-
};
33-
service_config.insert(domain.domain.clone(), domain_service_config);
34-
}
35-
3619
let mut alias_map = HashMap::new();
3720
for domain in conf.domains.iter() {
3821
if let Some(alias_host_list) = domain.alias.as_ref() {
@@ -43,8 +26,6 @@ impl ServiceConfig {
4326
}
4427

4528
ServiceConfig {
46-
default,
47-
inner: service_config,
4829
host_alias: Arc::new(alias_map),
4930
}
5031
}

0 commit comments

Comments
 (0)