neon_arch commited on
Commit
0d1213a
1 Parent(s): 68456fc

Adds temporary fixes for #1

Browse files
Files changed (3) hide show
  1. Cargo.lock +128 -0
  2. Cargo.toml +1 -0
  3. src/bin/websurfx.rs +34 -1
Cargo.lock CHANGED
@@ -268,6 +268,55 @@ dependencies = [
268
  "alloc-no-stdlib",
269
  ]
270
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  [[package]]
272
  name = "askama_escape"
273
  version = "0.10.3"
@@ -429,6 +478,48 @@ version = "1.0.0"
429
  source = "registry+https://github.com/rust-lang/crates.io-index"
430
  checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
431
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
  [[package]]
433
  name = "cloudabi"
434
  version = "0.0.3"
@@ -438,6 +529,12 @@ dependencies = [
438
  "bitflags",
439
  ]
440
 
 
 
 
 
 
 
441
  [[package]]
442
  name = "convert_case"
443
  version = "0.4.0"
@@ -965,6 +1062,12 @@ version = "0.12.3"
965
  source = "registry+https://github.com/rust-lang/crates.io-index"
966
  checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
967
 
 
 
 
 
 
 
968
  [[package]]
969
  name = "hermit-abi"
970
  version = "0.2.6"
@@ -1228,6 +1331,18 @@ version = "2.7.2"
1228
  source = "registry+https://github.com/rust-lang/crates.io-index"
1229
  checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f"
1230
 
 
 
 
 
 
 
 
 
 
 
 
 
1231
  [[package]]
1232
  name = "itoa"
1233
  version = "0.4.8"
@@ -2585,6 +2700,12 @@ version = "0.3.0"
2585
  source = "registry+https://github.com/rust-lang/crates.io-index"
2586
  checksum = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc"
2587
 
 
 
 
 
 
 
2588
  [[package]]
2589
  name = "syn"
2590
  version = "0.15.44"
@@ -3044,6 +3165,12 @@ version = "0.7.6"
3044
  source = "registry+https://github.com/rust-lang/crates.io-index"
3045
  checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
3046
 
 
 
 
 
 
 
3047
  [[package]]
3048
  name = "uuid"
3049
  version = "0.7.4"
@@ -3196,6 +3323,7 @@ version = "0.1.0"
3196
  dependencies = [
3197
  "actix-files",
3198
  "actix-web",
 
3199
  "fake-useragent",
3200
  "handlebars",
3201
  "reqwest 0.11.16",
 
268
  "alloc-no-stdlib",
269
  ]
270
 
271
+ [[package]]
272
+ name = "anstream"
273
+ version = "0.3.0"
274
+ source = "registry+https://github.com/rust-lang/crates.io-index"
275
+ checksum = "9e579a7752471abc2a8268df8b20005e3eadd975f585398f17efcfd8d4927371"
276
+ dependencies = [
277
+ "anstyle",
278
+ "anstyle-parse",
279
+ "anstyle-query",
280
+ "anstyle-wincon",
281
+ "colorchoice",
282
+ "is-terminal",
283
+ "utf8parse",
284
+ ]
285
+
286
+ [[package]]
287
+ name = "anstyle"
288
+ version = "1.0.0"
289
+ source = "registry+https://github.com/rust-lang/crates.io-index"
290
+ checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d"
291
+
292
+ [[package]]
293
+ name = "anstyle-parse"
294
+ version = "0.2.0"
295
+ source = "registry+https://github.com/rust-lang/crates.io-index"
296
+ checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee"
297
+ dependencies = [
298
+ "utf8parse",
299
+ ]
300
+
301
+ [[package]]
302
+ name = "anstyle-query"
303
+ version = "1.0.0"
304
+ source = "registry+https://github.com/rust-lang/crates.io-index"
305
+ checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
306
+ dependencies = [
307
+ "windows-sys 0.48.0",
308
+ ]
309
+
310
+ [[package]]
311
+ name = "anstyle-wincon"
312
+ version = "1.0.0"
313
+ source = "registry+https://github.com/rust-lang/crates.io-index"
314
+ checksum = "4bcd8291a340dd8ac70e18878bc4501dd7b4ff970cfa21c207d36ece51ea88fd"
315
+ dependencies = [
316
+ "anstyle",
317
+ "windows-sys 0.48.0",
318
+ ]
319
+
320
  [[package]]
321
  name = "askama_escape"
322
  version = "0.10.3"
 
478
  source = "registry+https://github.com/rust-lang/crates.io-index"
479
  checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
480
 
481
+ [[package]]
482
+ name = "clap"
483
+ version = "4.2.4"
484
+ source = "registry+https://github.com/rust-lang/crates.io-index"
485
+ checksum = "956ac1f6381d8d82ab4684768f89c0ea3afe66925ceadb4eeb3fc452ffc55d62"
486
+ dependencies = [
487
+ "clap_builder",
488
+ "clap_derive",
489
+ "once_cell",
490
+ ]
491
+
492
+ [[package]]
493
+ name = "clap_builder"
494
+ version = "4.2.4"
495
+ source = "registry+https://github.com/rust-lang/crates.io-index"
496
+ checksum = "84080e799e54cff944f4b4a4b0e71630b0e0443b25b985175c7dddc1a859b749"
497
+ dependencies = [
498
+ "anstream",
499
+ "anstyle",
500
+ "bitflags",
501
+ "clap_lex",
502
+ "strsim",
503
+ ]
504
+
505
+ [[package]]
506
+ name = "clap_derive"
507
+ version = "4.2.0"
508
+ source = "registry+https://github.com/rust-lang/crates.io-index"
509
+ checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4"
510
+ dependencies = [
511
+ "heck",
512
+ "proc-macro2 1.0.56",
513
+ "quote 1.0.26",
514
+ "syn 2.0.15",
515
+ ]
516
+
517
+ [[package]]
518
+ name = "clap_lex"
519
+ version = "0.4.1"
520
+ source = "registry+https://github.com/rust-lang/crates.io-index"
521
+ checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1"
522
+
523
  [[package]]
524
  name = "cloudabi"
525
  version = "0.0.3"
 
529
  "bitflags",
530
  ]
531
 
532
+ [[package]]
533
+ name = "colorchoice"
534
+ version = "1.0.0"
535
+ source = "registry+https://github.com/rust-lang/crates.io-index"
536
+ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
537
+
538
  [[package]]
539
  name = "convert_case"
540
  version = "0.4.0"
 
1062
  source = "registry+https://github.com/rust-lang/crates.io-index"
1063
  checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
1064
 
1065
+ [[package]]
1066
+ name = "heck"
1067
+ version = "0.4.1"
1068
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1069
+ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
1070
+
1071
  [[package]]
1072
  name = "hermit-abi"
1073
  version = "0.2.6"
 
1331
  source = "registry+https://github.com/rust-lang/crates.io-index"
1332
  checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f"
1333
 
1334
+ [[package]]
1335
+ name = "is-terminal"
1336
+ version = "0.4.7"
1337
+ source = "registry+https://github.com/rust-lang/crates.io-index"
1338
+ checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f"
1339
+ dependencies = [
1340
+ "hermit-abi 0.3.1",
1341
+ "io-lifetimes",
1342
+ "rustix",
1343
+ "windows-sys 0.48.0",
1344
+ ]
1345
+
1346
  [[package]]
1347
  name = "itoa"
1348
  version = "0.4.8"
 
2700
  source = "registry+https://github.com/rust-lang/crates.io-index"
2701
  checksum = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc"
2702
 
2703
+ [[package]]
2704
+ name = "strsim"
2705
+ version = "0.10.0"
2706
+ source = "registry+https://github.com/rust-lang/crates.io-index"
2707
+ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
2708
+
2709
  [[package]]
2710
  name = "syn"
2711
  version = "0.15.44"
 
3165
  source = "registry+https://github.com/rust-lang/crates.io-index"
3166
  checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
3167
 
3168
+ [[package]]
3169
+ name = "utf8parse"
3170
+ version = "0.2.1"
3171
+ source = "registry+https://github.com/rust-lang/crates.io-index"
3172
+ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
3173
+
3174
  [[package]]
3175
  name = "uuid"
3176
  version = "0.7.4"
 
3323
  dependencies = [
3324
  "actix-files",
3325
  "actix-web",
3326
+ "clap",
3327
  "fake-useragent",
3328
  "handlebars",
3329
  "reqwest 0.11.16",
Cargo.toml CHANGED
@@ -15,3 +15,4 @@ actix-web = {version="4"}
15
  actix-files = {version="0.6.2"}
16
  serde_json = {version="*"}
17
  fake-useragent = {version="*"}
 
 
15
  actix-files = {version="0.6.2"}
16
  serde_json = {version="*"}
17
  fake-useragent = {version="*"}
18
+ clap = {version="*", features = ["derive"] }
src/bin/websurfx.rs CHANGED
@@ -1,12 +1,45 @@
 
 
1
  use websurfx::server::routes;
2
 
3
  use actix_files as fs;
4
  use actix_web::{web, App, HttpServer};
 
5
  use handlebars::Handlebars;
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  // The function that launches the main server and handle routing functionality
8
  #[actix_web::main]
9
  async fn main() -> std::io::Result<()> {
 
 
 
 
10
  let mut handlebars: Handlebars = Handlebars::new();
11
 
12
  handlebars
@@ -29,7 +62,7 @@ async fn main() -> std::io::Result<()> {
29
  .default_service(web::route().to(routes::not_found)) // error page
30
  })
31
  // Start server on 127.0.0.1:8080
32
- .bind(("127.0.0.1", 8080))?
33
  .run()
34
  .await
35
  }
 
1
+ use std::ops::RangeInclusive;
2
+
3
  use websurfx::server::routes;
4
 
5
  use actix_files as fs;
6
  use actix_web::{web, App, HttpServer};
7
+ use clap::{command, Parser};
8
  use handlebars::Handlebars;
9
 
10
+ #[derive(Parser, Debug, Default)]
11
+ #[clap(author = "neon_arch", version, about = "Websurfx server application")]
12
+ #[command(propagate_version = true)]
13
+ struct CliArgs {
14
+ #[clap(default_value_t = 8080, short, long,value_parser = is_port_in_range)]
15
+ /// provide port number in range [1024-65536] to launch the server on.
16
+ port: u16,
17
+ }
18
+
19
+ const PORT_RANGE: RangeInclusive<usize> = 1024..=65535;
20
+
21
+ fn is_port_in_range(s: &str) -> Result<u16, String> {
22
+ let port: usize = s
23
+ .parse()
24
+ .map_err(|_| format!("`{s}` is not a valid port number"))?;
25
+ if PORT_RANGE.contains(&port) {
26
+ Ok(port as u16)
27
+ } else {
28
+ Err(format!(
29
+ "port not found in range {}-{}",
30
+ PORT_RANGE.start(),
31
+ PORT_RANGE.end()
32
+ ))
33
+ }
34
+ }
35
+
36
  // The function that launches the main server and handle routing functionality
37
  #[actix_web::main]
38
  async fn main() -> std::io::Result<()> {
39
+ let args = CliArgs::parse();
40
+
41
+ println!("started server on port {}", args.port);
42
+
43
  let mut handlebars: Handlebars = Handlebars::new();
44
 
45
  handlebars
 
62
  .default_service(web::route().to(routes::not_found)) // error page
63
  })
64
  // Start server on 127.0.0.1:8080
65
+ .bind(("127.0.0.1", args.port))?
66
  .run()
67
  .await
68
  }