88 saveFile,
99 deleteFile,
1010 } = require ( './lib/fswrapper' ) ,
11+ {
12+ ensureDir
13+ } = require ( 'fs-extra' ) ,
1114 path = require ( 'path' ) ,
1215 crypto = require ( 'crypto' ) ,
1316 Response = require ( './lib/Response' ) ,
1922 catchAll = res => {
2023 res . setHeader ( 'Content-Type' , 'application/json' ) ;
2124 res . json ( config ) ;
22- } ;
25+ } ,
26+ find = opt => new Promise (
27+ ( res , rej ) => op . find ( opt ,
28+ ( e , p ) => e ? rej ( e ) : res ( p )
29+ )
30+ ) ;
2331
2432app . all ( config . ping , ( req , res ) => {
2533 res . setHeader ( 'Content-Type' , 'application/json' ) ;
@@ -146,13 +154,14 @@ app.delete( config.proxy, ( req, res ) => {
146154app . all ( config . docs , ( req , res ) => catchAll ( res ) ) ;
147155app . all ( '*' , ( req , res ) => catchAll ( res ) ) ;
148156
149- op . find (
150- {
151- startingPort : config . port ,
152- endingPort : config . port + 50
153- } ,
154- ( e , p ) => app . listen (
155- p ,
156- ( ) => console . log ( `BasicFS running on ${ lanIP } :${ p } ` )
157+
158+ ensureDir ( config . publicDirectory )
159+ . then (
160+ ( ) => find ( { startingPort : config . port , endingPort : config . port + 50 } )
157161 )
158- ) ;
162+ . then (
163+ port => app . listen (
164+ port ,
165+ ( ) => console . log ( `BasicFS running on ${ lanIP } :${ port } ` )
166+ )
167+ ) ;
0 commit comments