Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
duniter-gva
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
modules
duniter-gva
Commits
a09ef437
Commit
a09ef437
authored
4 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
feat(conf): allow to disable playground
parent
ec334ef7
No related branches found
No related tags found
No related merge requests found
Pipeline
#12643
passed
4 years ago
Stage: tests
Stage: quality
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
conf/src/lib.rs
+13
-3
13 additions, 3 deletions
conf/src/lib.rs
src/lib.rs
+37
-15
37 additions, 15 deletions
src/lib.rs
with
50 additions
and
18 deletions
conf/src/lib.rs
+
13
−
3
View file @
a09ef437
...
...
@@ -30,10 +30,12 @@ pub struct GvaConf {
#[serde(default
=
"ip4_default"
)]
pub
ip4
:
Ipv4Addr
,
pub
ip6
:
Option
<
Ipv6Addr
>
,
#[serde(default
=
"port_default"
)]
pub
port
:
u16
,
#[serde(default
=
"path_default"
)]
pub
path
:
String
,
#[serde(default
=
"playground_default"
)]
pub
playground
:
bool
,
#[serde(default
=
"port_default"
)]
pub
port
:
u16
,
pub
remote_host
:
Option
<
String
>
,
pub
remote_port
:
Option
<
u16
>
,
pub
remote_path
:
Option
<
String
>
,
...
...
@@ -54,6 +56,10 @@ fn path_default() -> String {
"gva"
.to_owned
()
}
const
fn
playground_default
()
->
bool
{
true
}
const
fn
port_default
()
->
u16
{
30_901
}
...
...
@@ -71,8 +77,9 @@ impl Default for GvaConf {
enabled
:
false
,
ip4
:
ip4_default
(),
ip6
:
Some
(
ip6_default
()),
port
:
port_default
(),
path
:
path_default
(),
port
:
port_default
(),
playground
:
playground_default
(),
remote_host
:
None
,
remote_port
:
None
,
remote_path
:
None
,
...
...
@@ -150,6 +157,9 @@ impl GvaCommand {
.msg
(
format!
(
"Path ? [{}]"
,
conf
.path
))
.default
(
conf
.path
)
.get
();
// playground
let
res
=
input
()
.msg
(
"Enable playground ? [Y/n]"
)
.default
(
'Y'
)
.get
();
conf
.playground
=
res
!=
'n'
;
// remoteHost
if
let
Some
(
ref
remote_host
)
=
conf
.remote_host
{
let
new_remote_host
=
input
()
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
37
−
15
View file @
a09ef437
...
...
@@ -280,10 +280,9 @@ impl GvaModule {
);
let
gva_playground_route
=
warp_
::
gva_playground_route
(
&
conf
);
let
gva_subscription_route
=
warp_
::
gva_subscription_route
(
&
conf
,
gva_schema
.clone
());
let
routes
=
gva_route
.or
(
gva_subscription_route
)
.or
(
gva_playground_route
)
.recover
(|
err
:
Rejection
|
async
move
{
// Define recover function
let
recover_func
=
|
err
:
Rejection
|
async
move
{
if
let
Some
(
warp_
::
BadRequest
(
err
))
=
err
.find
()
{
return
Ok
::
<
_
,
Infallible
>
(
warp
::
reply
::
with_status
(
err
.to_string
(),
...
...
@@ -295,9 +294,32 @@ impl GvaModule {
"INTERNAL_SERVER_ERROR"
.to_string
(),
http
::
StatusCode
::
INTERNAL_SERVER_ERROR
,
))
})
;
}
;
// Start warp server
if
conf
.playground
{
Self
::
run_warp_server
(
&
conf
,
gva_route
.or
(
gva_subscription_route
)
.or
(
gva_playground_route
)
.recover
(
recover_func
),
)
.await
}
else
{
Self
::
run_warp_server
(
&
conf
,
gva_route
.or
(
gva_subscription_route
)
.recover
(
recover_func
),
)
.await
}
}
async
fn
run_warp_server
<
F
>
(
conf
:
&
GvaConf
,
routes
:
F
)
where
F
:
warp
::
Filter
<
Error
=
Infallible
>
+
Clone
+
Send
+
Sync
+
'static
,
F
::
Extract
:
warp
::
Reply
,
{
log
::
info!
(
"GVA server listen on http://{}:{}/{}"
,
conf
.ip4
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment