Initial version of the router class (not yet implemented)
This commit is contained in:
parent
02a97863ab
commit
870f7c6f08
1
server/.gitignore
vendored
Normal file
1
server/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.out
|
@ -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../
|
||||
```
|
||||
|
3
server/application/application.hpp
Normal file
3
server/application/application.hpp
Normal file
@ -0,0 +1,3 @@
|
||||
#include "router.hpp"
|
||||
|
||||
#include "router.inl"
|
27
server/application/router.hpp
Normal file
27
server/application/router.hpp
Normal 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
|
34
server/application/router.inl
Normal file
34
server/application/router.inl
Normal 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
|
@ -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;
|
||||
}
|
||||
|
@ -1,2 +0,0 @@
|
||||
#include "uv/uv.hpp"
|
||||
#include "http/http.hpp"
|
Loading…
Reference in New Issue
Block a user