66import express .utils .Status ;
77import express .utils .Utils ;
88
9- import java .io .File ;
109import java .io .IOException ;
1110import java .nio .file .Files ;
1211import java .nio .file .Path ;
2019 * @author Simon Reinisch
2120 * An middleware to provide access to static server-files.
2221 */
23- final class FileProvider implements HttpRequest {
22+ public final class FileProvider implements HttpRequest {
2423
2524 private final Logger LOGGER ;
2625 private FileProviderOptions OPTIONS ;
@@ -32,19 +31,26 @@ final class FileProvider implements HttpRequest {
3231 }
3332
3433 FileProvider (String root , FileProviderOptions options ) throws IOException {
35- File rootDir = new File (root );
34+ Path rootDir = Paths . get (root );
3635
37- if (!rootDir .exists () || !rootDir .isDirectory ())
36+ if (!Files .exists (rootDir ) || !Files .isDirectory (rootDir ))
3837 throw new IOException (rootDir + " does not exists or isn't an directory." );
3938
40- this .ROOT = rootDir .getAbsolutePath ();
39+ this .ROOT = rootDir .toAbsolutePath (). toString ();
4140 this .OPTIONS = options ;
4241 }
4342
4443 @ Override
4544 public void handle (Request req , Response res ) {
4645 String path = req .getURI ().getPath ();
4746
47+ // Check context
48+ String context = req .getContext ();
49+ if (path .indexOf (context ) == 0 ) {
50+ path = path .substring (context .length ());
51+ }
52+
53+ // If the path is empty try index.html
4854 if (path .length () <= 1 )
4955 path = "index.html" ;
5056
0 commit comments