Initial version of the router class (not yet implemented)

This commit is contained in:
buda 2015-09-17 02:26:48 +02:00
parent 02a97863ab
commit 870f7c6f08
7 changed files with 79 additions and 16 deletions

1
server/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.out

View File

@ -2,7 +2,7 @@
* https://github.com/libuv/libuv
```{engine='bash'}
```
sh autogen.sh
./configure
make
@ -12,14 +12,20 @@ make install
* https://github.com/joyent/http-parser
```{engine='bash'}
```
make
make install -stdlib=libstdc++ -lstdc++ (OSX)
make install
```
* https://github.com/c9s/r3
```
brew install r3 (OSX)
```
## Test compile
```{engine='bash'}
clang++ -std=c++11 test.cpp -o test -luv -lhttp_parser -I../
```
```
clang++ -std=c++11 test.cpp -o test.out -luv -lhttp_parser -I../
```

View File

@ -0,0 +1,3 @@
#include "router.hpp"
#include "router.inl"

View File

@ -0,0 +1,27 @@
#ifndef MEMGRAPH_SERVER_APPLICATION_ROUTER_HPP
#define MEMGRAPH_SERVER_APPLICATION_ROUTER_HPP
// TODO: find more appropriate way to include header files
#include "../uv/uv.hpp"
#include "../http/http.hpp"
namespace application
{
// TODO: find out more appropriate name, like express
class Router
{
private:
uv::UvLoop loop;
http::HttpServer server;
http::Ipv4 ip;
public:
Router(const http::Ipv4& ip);
void get(const std::string path, http::request_cb_t callback);
void listen();
~Router();
};
}
#endif

View File

@ -0,0 +1,34 @@
#ifndef MEMGRAPH_SERVER_APPLICATION_ROUTER_INL
#define MEMGRAPH_SERVER_APPLICATION_ROUTER_INL
#include "router.hpp"
namespace application
{
Router::Router(const http::Ipv4& ip) : server(loop), ip(ip)
{
}
void Router::get(const std::string path, http::request_cb_t callback)
{
}
void Router::listen()
{
server.listen(ip, [](http::Request& req, http::Response& res) {
res.send(req.url);
});
std::cout << "Server is UP" << std::endl;
loop.run(uv::UvLoop::Mode::Default);
}
Router::~Router()
{
}
}
#endif

View File

@ -1,19 +1,13 @@
#include <iostream>
#include "uvmachine.hpp"
#include "application/application.hpp"
int main(void)
{
uv::UvLoop loop;
http::HttpServer server(loop);
http::Ipv4 ip("0.0.0.0", 3400);
server.listen(ip, [](http::Request& req, http::Response& res) {
res.send(req.url);
});
loop.run(uv::UvLoop::Mode::Default);
application::Router router(ip);
router.listen();
return 0;
}

View File

@ -1,2 +0,0 @@
#include "uv/uv.hpp"
#include "http/http.hpp"