-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:add opt CORS #92
Conversation
Maybe need add a example in config-dist.toml |
I have a good idea We can design look like this, Because CORS belong http, So: [http]
listen = "[::]:7777"
# I think default should disable
core = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, last version is more good
config-dist.toml
Outdated
@@ -30,3 +30,16 @@ urls = [ | |||
# Default: info | |||
# Values: off, error, warn, info, debug, trace | |||
# level = "warn" | |||
|
|||
[http] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should only one [http]
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This config begin is a listen
right?
Actually, this listen
and cors
belong [http]
We need changed config, add a [http]
block, and move listen
to [http]
, after add core
to http
config-dist.toml
Outdated
|
||
[http] | ||
listen = "[::]:7777" | ||
cors = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to describe core
item
You can describe:
# Cross-Origin Resource Sharing (CORS)
# reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
cors = false
config-dist.toml
Outdated
listen = "[::]:7777" | ||
cors = false | ||
|
||
#[http] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this
src/config.rs
Outdated
@@ -16,6 +18,7 @@ pub struct Config { | |||
pub auth: Auth, | |||
#[serde(default = "default_log")] | |||
pub log: Log, | |||
pub enable_cors: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you move to core in http block, this field name is changed
src/config.rs
Outdated
@@ -157,6 +160,7 @@ impl Config { | |||
listen: default_listen(), | |||
auth: Default::default(), | |||
log: default_log(), | |||
enable_cors: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
field name is changed
src/config.rs
Outdated
|
||
|
||
pub fn cors_layer() -> CorsLayer { | ||
let config_cors = fs::read_to_string("config-dist.toml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What this? read config-dist.toml
should only read one time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cors_layer()
should a params, enable: boolean
src/config.rs
Outdated
eprintln!("Unable to read config-dist.toml"); | ||
String::from(r#" | ||
[http] | ||
listen = "[::]:7777" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why together display listen
error and cors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Config struct should changed
look like:
pub struct Http {
pub listen: String,
pub core: Boolean,
}
config-dist.toml
Outdated
@@ -30,3 +30,16 @@ urls = [ | |||
# Default: info | |||
# Values: off, error, warn, info, debug, trace | |||
# level = "warn" | |||
|
|||
[http] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This config begin is a listen
right?
Actually, this listen
and cors
belong [http]
We need changed config, add a [http]
block, and move listen
to [http]
, after add core
to http
src/config.rs
Outdated
|
||
|
||
pub fn cors_layer() -> CorsLayer { | ||
let config_cors = fs::read_to_string("config-dist.toml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cors_layer()
should a params, enable: boolean
src/main.rs
Outdated
@@ -79,6 +79,7 @@ async fn main() { | |||
config: cfg.clone(), | |||
}; | |||
let auth_layer = ValidateRequestHeaderLayer::custom(ManyValidate::new(cfg.auth)); | |||
let cors = cors_layer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should cors enable in here, For example cfg.http.core
No description provided.