Small refactor and interface update

This commit is contained in:
Alex Hultman
2018-06-24 00:16:54 +02:00
parent d731bfcc47
commit a2fe871e63
7 changed files with 264 additions and 329 deletions
+11 -12
View File
@@ -1,7 +1,7 @@
// this is roughly the interfaces I plan for (with changes and additional helpers added with time)
// much speaks for a header-only or header-mostly implementation now that uSockets is properly isolating its internal headers
#include "Context.h"
#include "App.h"
#include "HttpRouter.h"
int main() {
@@ -9,24 +9,23 @@ int main() {
std::cout << "HttpSocket size: " << sizeof(HttpSocket<true>::Data) << std::endl;
char *buffer = new char[512];
// SSL options are given via uSockets structure
us_ssl_socket_context_options options = {};
options.key_file_name = "/home/alexhultman/uWebSockets/misc/ssl/key.pem";
options.cert_file_name = "/home/alexhultman/uWebSockets/misc/ssl/cert.pem";
options.passphrase = "1234";
uWS::SSLApp c(uWS::SSLOptions()
.keyFileName("/home/alexhultman/uWebSockets/misc/ssl/key.pem")
.certFileName("/home/alexhultman/uWebSockets/misc/ssl/cert.pem")
.passphrase("1234"));
//uWS::App c;
//uWS::SSLContext c(options);
uWS::Context c;
c.route("GET", "/", [buffer](auto *s, HttpRequest *req, auto *args) {
c.onGet("/", [buffer](auto *s, HttpRequest *req, auto *args) {
s->writeStatus(200)->writeHeader("Hello", "World")->end(buffer, 512);
}).route("GET", "/wrong", [buffer](auto *s, HttpRequest *req, auto *args) {
}).onGet("/wrong", [buffer](auto *s, HttpRequest *req, auto *args) {
std::cout << "Wrong way!" << std::endl;
}).onWebSocket([]() {
}).listen("localhost", 3000, 0);
uWS::defaultHub.run();
uWS::run();
}