Skip to content
Snippets Groups Projects
Commit 38a8e080 authored by Elisa Giglio's avatar Elisa Giglio
Browse files

aggiornamenti webapp

parent 1cf7390a
No related branches found
No related tags found
No related merge requests found
......@@ -22,35 +22,29 @@ public class Resources implements HttpHandler {
String requestURI = exchange.getRequestURI().toASCIIString().replace("/secured/home/","/");
String requestMethod = exchange.getRequestMethod();
if (Helper.isSameString(requestMethod, "GET")) {
String response = getLocalPage(requestURI);
if(response.equals("fail")){
//nel caso in cui non ci sia il file (perche non stato scaricato), allora creo un file fittizzio per non far crashare tutto il resto
String[] requestedPath = requestURI.split("/");
// get the last element of requestedPath and remove .js
String[] requestedPage = requestedPath[requestedPath.length-1].split("\\.");
String className = requestedPage[0];
// make requested page with the first letter capitalized
className = className.substring(0, 1).toUpperCase() + className.substring(1);
response = "class "+className+"{}\nexport default " +className;
}
List<String> strlist = new ArrayList<>();
switch (requestURI.substring(1, 4)) {
case "js/" : strlist.add("text/javascript"); break;
case "css" : strlist.add("text/css"); break;
// case "con" : strlist.add("text/plain"); break;
// case "con" : strlist.add("application/json"); break;
// default : strlist.add("text/plain"); break;
default: strlist.add("text"); break;
}
exchange.getResponseHeaders().put("content-type", strlist);
exchange.sendResponseHeaders(200, response.getBytes().length);
OutputStream os = exchange.getResponseBody();
os.write(response.getBytes());
os.close();
} else {
if (!Helper.isSameString(requestMethod, "GET")) {
Helper.methodNotAllowed(exchange);
return;
}
String response = getLocalPage(requestURI);
if(response == null || Helper.isSameString(response, "fail")){
//nel caso in cui non ci sia il file (perche non stato scaricato), allora creo un file fittizzio per non far crashare tutto il resto
String[] requestedPath = requestURI.split("/");
// get the last element of requestedPath and remove .js
String[] requestedPage = requestedPath[requestedPath.length-1].split("\\.");
String className = requestedPage[0];
// make requested page with the first letter capitalized
className = className.substring(0, 1).toUpperCase() + className.substring(1);
response = "class "+className+"{}\nexport default " +className;
}
List<String> strlist = new ArrayList<>();
switch (requestURI.substring(1, 4)) {
case "js/" : strlist.add("text/javascript"); break;
case "css" : strlist.add("text/css"); break;
default: strlist.add("text"); break;
}
exchange.getResponseHeaders().put("content-type", strlist);
Helper.sendResponseOk(response, exchange);
}
private static String getLocalPage(String uri) {
......
......@@ -80,7 +80,6 @@ public class Server {
server.createContext("/js/authentication/",new Resources());
server.createContext("/js/templates/",new Resources());
server.createContext("/css/",new Resources());
// server.createContext("/conf/",new Resources());
server.createContext("/res/",new ImageRes());
server.createContext("/secured/home/js/",new Resources());
server.createContext("/secured/home/css/",new Resources());
......
3A138A02CF04B956146CEDBAA263F0DCA29654FA
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment