app.d 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Collie - An asynchronous event-driven network framework using Dlang development
  3. *
  4. * Copyright (C) 2015-2016 Shanghai Putao Technology Co., Ltd
  5. *
  6. * Developer: putao's Dlang team
  7. *
  8. * Licensed under the Apache-2.0 License.
  9. *
  10. */
  11. import std.stdio;
  12. import std.experimental.logger;
  13. import std.exception;
  14. import std.typecons;
  15. import std.functional;
  16. import std.parallelism;
  17. import collie.socket;
  18. import collie.codec.http;
  19. import collie.codec.http.server;
  20. debug {
  21. extern(C) __gshared string[] rt_options = [ "gcopt=profile:1"];// maxPoolSize:50" ];
  22. }
  23. void main()
  24. {
  25. RequestHandler newHandler(RequestHandler,HTTPMessage msg)
  26. {
  27. import get;
  28. import post;
  29. if(msg.method == HTTPMethod.HTTP_GET)
  30. return new GetHandler();
  31. if(msg.method == HTTPMethod.HTTP_POST)
  32. return new PostHandler();
  33. return null;
  34. }
  35. writeln("Edit source/app.d to start your project.");
  36. globalLogLevel(LogLevel.warning);
  37. HTTPServerOptions option = new HTTPServerOptions();
  38. option.handlerFactories.insertBack(&newHandler);
  39. option.threads = totalCPUs;
  40. HttpServer server = new HttpServer(option);
  41. HTTPServerOptions.IPConfig ipconfig ;
  42. ipconfig.address = new InternetAddress("0.0.0.0", 8085);
  43. HTTPServerOptions.IPConfig ipconfig2 ;
  44. ipconfig2.address = new Internet6Address("0::0", 8085);
  45. server.addBind(ipconfig);
  46. server.addBind(ipconfig2);
  47. server.start();
  48. }