@Override
	public Response serve(IHTTPSession session) {
		Method method = session.getMethod();
		String uri = session.getUri();
		Map<String, String> parms = session.getParms();

		File rootDirectory = new File("www");

		Response res = new NanoHTTPD.Response("jErgoViewer - Not Found");
		if (uri.endsWith(".do")) {
			if (uri.equals("/list_kml.do"))
			{
				res = listKml(session);
			}
			else if (uri.equals("/stats.do"))
			{
				res = getStats(session);
			}
		} else {
			if (uri.equals("/"))
			{
				uri = "index.html";
			}

			// static file
			File requestedFile = new File(rootDirectory, uri);
			if (requestedFile.exists())
			{
				try {
					InputStream fileInputStream = new FileInputStream(requestedFile);
					
					String extension = "";
					int i = requestedFile.getName().lastIndexOf('.');
					if (i > 0) {
					    extension =  requestedFile.getName().substring(i+1);
					}

					String mimeType = mimeTypes.containsKey(extension) ? mimeTypes.get(extension) : "application/binary";
					
					res = new NanoHTTPD.Response(Status.OK, mimeType, fileInputStream);
				} catch (FileNotFoundException e) {
					res = new NanoHTTPD.Response(Status.NOT_FOUND, "text/plain", "Error: " + e.getMessage());
				}
			}

		}

		return res;

	}