package examples.files;

import com.vtence.molecule.WebServer;
import com.vtence.molecule.middlewares.ApacheCommonLogger;
import com.vtence.molecule.middlewares.FileServer;
import com.vtence.molecule.middlewares.StaticAssets;

import java.io.IOException;
import java.util.logging.Logger;

import static com.vtence.molecule.testing.ResourceLocator.locateOnClasspath;

public class StaticFilesExample {

    private final Logger logger;

    public StaticFilesExample(Logger logger) {
        this.logger = logger;
    }

    public void run(WebServer server) throws IOException {
        // Serve files in this directory, based on the path of the request.
        FileServer files = new FileServer(locateOnClasspath("examples/fox"));
        // Serve static assets (e.g. js files, images, css files, etc) for any request whose path starts
        // with one of the url prefixes specified (in this example, we're serving all requests).
        StaticAssets assets = new StaticAssets(files).serve("/");
        // If request targets a directory (i.e. request path ends with "/"),
        // serve the index.html file located in that directory (the default behavior).
        assets.index("index.html");

        // Log all accesses to the server in apache common log format
        server.add(new ApacheCommonLogger(logger))
              .start(assets);
    }

    public static void main(String[] args) throws IOException {
        // Let's log server access to the console, so we can see content we're serving
        StaticFilesExample example = new StaticFilesExample(Logging.toConsole());
        WebServer webServer = WebServer.create();
        example.run(webServer);
        System.out.println("Access at " + webServer.uri());
    }
}
@@ -360,16 +360,530 @@
 spath;%0A%0A
+/**%0A * %3Cp%3E%0A *     In this example we setup the server to run a single application that serves static files.%0A * %3C/p%3E%0A * %3Cp%3E%0A *     We want to serve the files located in the %3Ccode%3Esrc/test/resources/examples/fox%3C/code%3E directory.%0A *     We'd like a request to the root of the server to serve the %3Ccode%3Eindex.html%3C/code%3E file under that directory.%0A * %3C/p%3E%0A * %3Cp%3E%0A *     To see the server's activity, we use the apache common logger middleware to log all requests and status to the%0A *     standard output.%0A * %3C/p%3E%0A */%0A
 public c
@@ -1103,69 +1103,95 @@
 / Se
-rve files in this directory, based on the path of the request
+tup the file server and tell it to serve files located under the examples/fox directory
 .%0A  
@@ -1357,73 +1357,157 @@
 est 
-whose path starts%0A        // with one of the url prefixes
+starting at the root path.%0A        // This will in effect serve every request with static assets.%0A        // Typically you would specify more
  specifi
 ed (
@@ -1506,56 +1506,57 @@
 cifi
-ed (in 
+c pa
 th
-i
 s 
-example, we're serving all requests)
+to serve, such as /css, /js, /images, etc
 .%0A  
@@ -1633,16 +1633,18 @@
   // If 
+a 
 request 
@@ -1667,13 +1667,13 @@
 ory 
-(i.e.
+- the
  req
@@ -1699,10 +1699,10 @@
  %22/%22
-),
+ -
 %0A   
@@ -1833,19 +1833,45 @@
      // 
-Log
+The apache common logger logs
  all acc
@@ -1917,16 +1917,62 @@
 g format
+,%0A        // so we can see what we're serving.
 %0A       
@@ -2131,18 +2131,29 @@
  // 
-Let's
+We choose to
  log 
+all 
 serv
@@ -2161,16 +2161,18 @@
 r access
+es
  to the 
@@ -2182,45 +2182,8 @@
 sole
-, so we can see content we're serving
 %0A   
@@ -2410,8 +2410,9 @@
 %0A    %7D%0A%7D
+%0A

Add documentation to the simple example