1
- // Simple server for local testing.
2
-
1
+ // Simple local server
3
2
import * as path from "path" ;
4
3
import commandLineArgs from "command-line-args" ;
5
4
import esMain from "es-main" ;
6
- import LocalWebServer from "lws" ;
7
- import "lws-cors" ;
8
- import "lws-index" ;
9
- import "lws-log" ;
10
- import "lws-static" ;
5
+ import LocalWebServer from "local-web-server" ;
11
6
12
7
const ROOT_DIR = path . join ( process . cwd ( ) , "./" ) ;
13
8
@@ -19,35 +14,20 @@ export default async function serve(port) {
19
14
directory : ROOT_DIR ,
20
15
corsOpenerPolicy : "same-origin" ,
21
16
corsEmbedderPolicy : "require-corp" ,
22
- logFormat : "dev" ,
23
- stack : [ "lws-log" , "lws-cors" , "lws-static" , "lws-index" ] ,
24
17
} ) ;
25
- await verifyStartup ( ws , port ) ;
26
-
18
+ console . log ( `Server started on http://localhost:${ port } ` ) ;
27
19
process . on ( "exit" , ( ) => ws . server . close ( ) ) ;
28
-
29
20
return {
30
21
close ( ) {
31
22
ws . server . close ( ) ;
32
- } ,
23
+ }
33
24
} ;
34
25
}
35
26
36
- async function verifyStartup ( ws , port ) {
37
- await new Promise ( ( resolve , reject ) => {
38
- ws . server . on ( "listening" , ( ) => {
39
- console . log ( `Server started on http://localhost:${ port } ` ) ;
40
- resolve ( ) ;
41
- } ) ;
42
- ws . server . on ( "error" , ( e ) => {
43
- console . error ( "Error while starting the server" , e ) ;
44
- reject ( e ) ;
45
- } ) ;
46
- } ) ;
47
- }
48
-
49
27
function main ( ) {
50
- const optionDefinitions = [ { name : "port" , type : Number , defaultValue : 8010 , description : "Set the test-server port, The default value is 8010." } ] ;
28
+ const optionDefinitions = [
29
+ { name : "port" , type : Number , defaultValue : 8010 , description : "Set the test-server port, The default value is 8010." } ,
30
+ ] ;
51
31
const options = commandLineArgs ( optionDefinitions ) ;
52
32
serve ( options . port ) ;
53
33
}
0 commit comments