Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F41921372
app.rs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
app.rs
View Options
/* -------------------------------------------------------------
Limiting Factor :: axum :: App
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Project: Nasqueron
License: BSD-2-Clause
------------------------------------------------------------- */
use
axum
::
Router
;
use
log
::{
error
,
info
};
use
tokio
::
net
::
TcpListener
;
/* -------------------------------------------------------------
Re-exports from core
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
pub
use
limiting_factor_core
::
app
::
ServerConfig
;
/* -------------------------------------------------------------
Main application server
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
pub
struct
App
{
pub
config
:
ServerConfig
,
router
:
Router
,
}
impl
Default
for
App
{
fn
default
()
->
Self
{
Self
{
config
:
ServerConfig
::
from_env
(),
router
:
Router
::
new
(),
}
}
}
impl
App
{
pub
fn
new
(
config
:
ServerConfig
,
router
:
Router
)
->
Self
{
Self
{
config
,
router
,
}
}
pub
fn
from_config
(
config
:
ServerConfig
)
->
Self
{
Self
{
config
,
router
:
Router
::
new
(),
}
}
pub
fn
with_config
(
mut
self
,
config
:
ServerConfig
)
->
Self
{
self
.
config
=
config
;
self
}
fn
resolve_router
(
&
self
)
->
Router
{
if
self
.
config
.
mount_point
==
"/"
{
return
self
.
router
.
clone
();
}
Router
::
new
()
.
nest
(
&*
self
.
config
.
mount_point
,
self
.
router
.
clone
())
}
pub
async
fn
run
(
self
)
->
bool
{
let
app
=
self
.
resolve_router
();
let
socket_address
=
self
.
config
.
get_socket_address
();
info
!
(
"🚀 Starting server"
);
match
TcpListener
::
bind
(
&
socket_address
).
await
{
Ok
(
listener
)
=>
{
info
!
(
"Listening to {}"
,
socket_address
);
axum
::
serve
(
listener
,
app
).
await
.
unwrap
();
true
}
Err
(
error
)
=>
{
error
!
(
"{}"
,
error
);
false
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Aug 8, 02:50 (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3975201
Default Alt Text
app.rs (2 KB)
Attached To
Mode
rLF Limiting Factor
Attached
Detach File
Event Timeline
Log In to Comment