SNode.C
Loading...
Searching...
No Matches
ClientApp.cpp
Go to the documentation of this file.
1#include "express/legacy/in/WebApp.h"
2#include "express/middleware/StaticMiddleware.h"
3#include "log/Logger.h"
4
5#include <string>
6
7int main(int argc, char* argv[]) {
8 express::WebApp::init(argc, argv);
9 const express::legacy::in::WebApp app("OAuth2Client");
10
11 app.get("/oauth2", [] APPLICATION(req, res) {
12 // if (req.query("grant_type")) {}
13 if (!req->query("code").empty()) {
14 res->sendFile("/home/rathalin/projects/snode.c/src/oauth2/client_app/vue-frontend-oauth2-client/dist/index.html",
15 [req](int ret) {
16 if (ret != 0) {
17 PLOG(ERROR) << req->url;
18 }
19 });
20 /*
21 std::string tokenRequestUri{"http://localhost:8082/oauth2/token"};
22 tokenRequestUri += "?grant_type=authorization_code";
23 tokenRequestUri += "&code=" + req.query("code");
24 if (!req.query("state").empty()) {
25 tokenRequestUri += "&state=" + req.query("state");
26 }
27 tokenRequestUri += "&client_id=911a821a-ea2d-11ec-8e2e-08002771075f";
28 tokenRequestUri += "&redirect_uri=http://localhost:8081/oauth2";
29 VLOG(1) << "Recieving auth code from auth server: " << req.query("code") << ", requesting token from " << tokenRequestUri;
30 res.redirect(tokenRequestUri);
31 */
32 }
33 });
34
35 app.use(express::middleware::StaticMiddleware("/home/rathalin/projects/snode.c/src/oauth2/client_app/vue-frontend-oauth2-client/dist"));
36
37 app.listen(8081, [](const express::legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) {
38 switch (state) {
39 case core::socket::State::OK:
40 VLOG(1) << "OAuth2Client: connected to '" << socketAddress.toString() << "'";
41 break;
42 case core::socket::State::DISABLED:
43 VLOG(1) << "OAuth2Client: disabled";
44 break;
45 case core::socket::State::ERROR:
46 VLOG(1) << "OAuth2Client: error occurred";
47 break;
48 case core::socket::State::FATAL:
49 VLOG(1) << "OAuth2Client: fatal error occurred";
50 break;
51 }
52 });
53
54 return express::WebApp::start();
55}
#define APPLICATION(req, res)
Definition Router.h:45
static void init(int argc, char *argv[])
Definition WebApp.cpp:34
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
Definition WebApp.cpp:38
int main(int argc, char *argv[])