1
- use std:: collections :: HashMap ;
2
-
3
- use std :: path:: Path ;
4
- use std :: env ;
5
-
6
- use std :: sync :: { Arc , Mutex } ;
7
- use tokio:: time:: { self } ;
1
+ use std:: {
2
+ env ,
3
+ path:: Path ,
4
+ sync :: Arc ,
5
+ { net :: SocketAddr , path :: PathBuf }
6
+ } ;
7
+ use tokio:: time;
8
8
use async_trait:: async_trait;
9
+ use migration:: Migrator ;
10
+ use sea_orm:: DatabaseConnection ;
11
+ use reqwest:: Client ;
12
+ use tower_http:: normalize_path:: NormalizePathLayer ;
13
+ use tower_layer:: Layer ;
14
+ use axum_server:: tls_rustls:: RustlsConfig ;
15
+ use axum:: {
16
+ extract:: Host ,
17
+ handler:: HandlerWithoutStateExt ,
18
+ http:: { StatusCode , Uri } ,
19
+ response:: Redirect , Extension ,
20
+ } ;
9
21
use loco_rs:: {
10
22
app:: { AppContext , Hooks , Initializer } ,
11
23
boot:: { create_app, BootResult , StartMode } ,
12
24
controller:: AppRoutes ,
13
- db:: { self , truncate_table} ,
25
+ db:: truncate_table,
14
26
environment:: Environment ,
15
27
task:: Tasks ,
16
28
worker:: { AppWorker , Processor } ,
17
29
Result ,
18
30
} ;
19
- use migration:: { Migrator } ;
20
- use sea_orm:: DatabaseConnection ;
21
- use serde:: { Deserialize , Serialize } ;
22
31
23
32
use crate :: {
24
- controllers, initializers,
25
- models:: _entities:: { devices, notes, users} ,
26
33
tasks,
34
+ controllers,
35
+ initializers,
36
+ controllers:: ws:: ConnectionManager ,
37
+ models:: _entities:: { devices, users} ,
27
38
} ;
28
39
29
- use reqwest:: { Client } ;
30
- use tower_http:: normalize_path:: NormalizePathLayer ;
31
- use tower_layer:: Layer ;
32
- use tokio:: sync:: { mpsc, oneshot, RwLock } ;
33
-
34
- use axum:: {
35
- extract:: Host ,
36
- handler:: HandlerWithoutStateExt ,
37
- http:: { StatusCode , Uri } ,
38
- response:: Redirect , Extension ,
39
- } ;
40
- use axum_server:: tls_rustls:: RustlsConfig ;
41
- use std:: { net:: SocketAddr , path:: PathBuf } ;
42
-
43
-
44
- #[ derive( Serialize , Deserialize , Clone ) ]
45
- struct JsonRpcCommand {
46
- id : String ,
47
- method : String ,
48
- params : serde_json:: Value ,
49
- }
50
-
51
- #[ derive( Serialize , Deserialize , Clone ) ]
52
- struct JsonRpcResponse {
53
- id : String ,
54
- result : Option < serde_json:: Value > ,
55
- error : Option < serde_json:: Value > ,
56
- }
57
-
58
- type SharedState = Arc < RwLock < App > > ;
59
-
60
- use crate :: controllers:: ws:: ConnectionManager ;
61
-
62
- pub struct App {
63
- // command_sender: mpsc::Sender<JsonRpcCommand>,
64
- // pending_commands: Arc<Mutex<HashMap<String, oneshot::Sender<JsonRpcResponse>>>>,
65
- // offline_queues: Arc<Mutex<HashMap<String, Vec<JsonRpcCommand>>>>, // offline queue for each device
66
- }
40
+ pub struct App { }
67
41
#[ async_trait]
68
42
impl Hooks for App {
69
43
fn app_name ( ) -> & ' static str {
@@ -123,14 +97,13 @@ impl Hooks for App {
123
97
124
98
async fn truncate ( db : & DatabaseConnection ) -> Result < ( ) > {
125
99
truncate_table ( db, users:: Entity ) . await ?;
126
- truncate_table ( db, notes:: Entity ) . await ?;
127
100
Ok ( ( ) )
128
101
}
129
102
130
- async fn seed ( db : & DatabaseConnection , base : & Path ) -> Result < ( ) > {
131
- db:: seed :: < users:: ActiveModel > ( db, & base. join ( "users.yaml" ) . display ( ) . to_string ( ) ) . await ?;
103
+ async fn seed ( _db : & DatabaseConnection , _base : & Path ) -> Result < ( ) > {
104
+ // db::seed::<users::ActiveModel>(db, &base.join("users.yaml").display().to_string()).await?;
132
105
//db::seed::<notes::ActiveModel>(db, &base.join("notes.yaml").display().to_string()).await?;
133
- db:: seed :: < devices:: ActiveModel > ( db, & base. join ( "devices.yaml" ) . display ( ) . to_string ( ) ) . await ?;
106
+ // db::seed::<devices::ActiveModel>(db, &base.join("devices.yaml").display().to_string()).await?;
134
107
//db::seed::<routes::ActiveModel>(db, &base.join("routes.yaml").display().to_string()).await?;
135
108
//db::seed::<segments::ActiveModel>(db, &base.join("segments.yaml").display().to_string()).await?;
136
109
Ok ( ( ) )
@@ -159,20 +132,10 @@ impl Hooks for App {
159
132
}
160
133
} ) ;
161
134
162
-
163
-
164
- //let (command_sender, _command_receiver) = mpsc::channel(100);
165
- // let shared_state: Arc<RwLock<App>> = Arc::new(RwLock::new(App {
166
- // command_sender,
167
- // pending_commands: Arc::new(Mutex::new(HashMap::new())),
168
- // offline_queues: Arc::new(Mutex::new(HashMap::new())),
169
- // }));
170
135
let client = Client :: new ( ) ;
171
-
172
136
let router = router
173
137
. layer ( Extension ( client) )
174
138
. layer ( Extension ( connection_manager) ) ;
175
- //.layer(Extension(shared_state));
176
139
177
140
Ok ( router)
178
141
}
@@ -241,6 +204,7 @@ struct MyServerConfig {
241
204
binding : String
242
205
}
243
206
207
+ /*
244
208
async fn redirect_http_to_https(my_server_config: MyServerConfig) {
245
209
let config_clone = my_server_config.clone(); // Clone the config for the closure
246
210
@@ -274,4 +238,5 @@ async fn redirect_http_to_https(my_server_config: MyServerConfig) {
274
238
axum::serve(listener, redirect.into_make_service())
275
239
.await
276
240
.unwrap();
277
- }
241
+ }
242
+ */
0 commit comments