package server;

import static spark.Spark.exception;
import static spark.SparkBase.*;

import java.util.UUID;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import spark.Route;
import spark.Spark;

public class Server {

	public Server() {
		// DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
		mapper = new ObjectMapper();
		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	}

	public void start(Integer aPort) {
		port(aPort);
		staticFileLocation("/public");
		exception(Exception.class, (e, request, response) -> {
			response.status(500);
			response.header("Content-Type", "application/json");
			try {
				String publicErrorMessage = "Unknown error : " + UUID.randomUUID().toString();
				Exception message = new RuntimeException(publicErrorMessage);
				response.body(mapper.writeValueAsString(message));
				new RuntimeException(publicErrorMessage, e).printStackTrace();
			} catch (Exception e1) {
				e1.printStackTrace();
				// should not happen
				response.body("{\"error\":\"error\"}");
			}
		});
	}

	private ObjectMapper mapper;

	public void get(String path, Route route) {
		Spark.get(path, (request, response) -> {
			Object result = route.handle(request, response);
			response.status(200);
			response.header("Content-Type", "application/json");
			return mapper.writeValueAsString(result);
		});
	}

}

@@ -81,11 +81,115 @@
 ase.
-*;%0A
+port;%0Aimport static spark.SparkBase.staticFileLocation;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;
 %0Aimp
@@ -388,16 +388,98 @@
 rver %7B%0A%0A
+%09private ObjectMapper mapper;%0A%09private List%3CString%3E routes = new ArrayList%3C%3E();%0A%09%0A
 %09public 
@@ -1298,40 +1298,189 @@
 );%0A%09
-%7D%0A%0A%09private ObjectMapper mapper;
+%09%0A%09%09Spark.get(%22/%22, (request, response) -%3E %7B%0A%09%09%09response.status(200);%0A%09%09%09response.header(%22Content-Type%22, %22application/json%22);%0A%09%09%09return mapper.writeValueAsString(routes);%0A%09%09%7D);%0A%09%7D%0A%0A%09
 %0A%0A%09p
@@ -1522,16 +1522,49 @@
 oute) %7B%0A
+%09%09%0A%09%09routes.add(%22GET %22+path);%0A%09%09%0A
 %09%09Spark.

add descriptive