Advertisement
Guest User

hello

a guest
Jun 25th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. package hello;
  2.  
  3. import static spark.Spark.*;
  4. import spark.ModelAndView;
  5. import java.util.*;
  6. import spark.template.mustache.*;
  7.  
  8. public class MainServer {
  9.     public static void main(String[] args) {
  10.  
  11.         // Get port config of heroku on environment variable
  12.         ProcessBuilder process = new ProcessBuilder();
  13.         Integer port;
  14.         if (process.environment().get("PORT") != null) {
  15.             port = Integer.parseInt(process.environment().get("PORT"));
  16.         } else {
  17.             port = 8080;
  18.         }
  19.         port(port);
  20.  
  21.         //Delivery static file
  22.         staticFileLocation("/static");
  23.  
  24.         // Handle requests
  25.         get("/", (req, res) -> {
  26.  
  27.             Map map = new HashMap();
  28.             map.put("title", "Welcome to this world");
  29.             map.put("name", "Sam");
  30.  
  31.             return new ModelAndView(map, "hello.mustache");
  32.         }, new MustacheTemplateEngine());
  33.  
  34.         get("/hello", (req, res) -> "Hello World");
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement