Skip to content

Commit 514eee1

Browse files
committed
Added folder existence check
1 parent 5cd310f commit 514eee1

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

index.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const
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' ),
@@ -19,7 +22,12 @@ const
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

2432
app.all( config.ping, ( req, res ) => {
2533
res.setHeader( 'Content-Type', 'application/json' );
@@ -146,13 +154,14 @@ app.delete( config.proxy, ( req, res ) => {
146154
app.all( config.docs, ( req, res ) => catchAll( res ) );
147155
app.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+
);

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"dependencies": {
1818
"express": "^4.15.3",
1919
"formidable": "^1.1.1",
20+
"fs-extra": "^3.0.1",
2021
"mime": "^1.3.6",
2122
"openport": "0.0.4",
2223
"send": "^0.15.3"

0 commit comments

Comments
 (0)