-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
80 lines (51 loc) · 1.68 KB
/
main.cpp
File metadata and controls
80 lines (51 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#define EXPRESS_ALLOW_ZLIB_COMPRESSION 0
#include <nodepp/nodepp.h>
#include <nodepp/worker.h>
#include <nodepp/query.h>
#include <nodepp/json.h>
#include <nodepp/fs.h>
#include <express/http.h>
using namespace nodepp;
#include "./controller/controller.cpp"
void clients() {
auto file = fs::writable ( "./www/uikit.css" );
auto data = fs::read_file( "./package.json" ).await();
auto obj = json::parse ( data.value() );
for( auto x: obj["list"].as<array_t<object_t>>() ){
fetch_t args;
args.url = x.as<string_t>();
args.headers= header_t({ });
args.method = "GET";
auto fetch = http::fetch( args ).await();
if( !fetch.has_value() ) /*---*/ { break; }
if( fetch.value().status != 200 ){ break; }
while( fetch.value().is_available() )
{ file.write( fetch.value().read() ); }
}
process::exit();
}
void compile() {
if( process::is_child() ){ throw 0; }
auto app = express::http::add();
app.ALL([=]( express_http_t cli ){
console::log( "->", cli.path );
}); uk::controller( app );
app.listen( "0.0.0.0", 8000, []( ... ){
console::log( "-> http://localhost:8000" );
worker::add([=](){ clients(); return -1; });
});
}
void test() {
auto app = express::http::add();
app.ALL([=]( express_http_t cli ){
console::log( "->", cli.path );
});
app.USE( express::http::file( "./www" ) );
app.listen( "0.0.0.0", 8000, []( ... ){
console::log( "-> http://localhost:8000" );
});
}
void onMain(){
if( process::env::get("mode") == "test" )
{ test(); } else { compile(); }
}