Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (46 loc) · 1.58 KB
/
Copy pathmain.cpp
File metadata and controls
63 lines (46 loc) · 1.58 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
#include <nodepp/nodepp.h>
#include <nodepp/http.h>
#include <nodepp/date.h>
using namespace nodepp;
void onMain(){
auto server = http::server([=]( http_t cli ){
console::log( cli.path, cli.get_fd() );
cli.write_header( 200, header_t({
{ "Content-Type" , "text/html" },
{ "Transfer-Encoding", "chunked" },
// { "Content-Length", string::to_string( file.size() ) }
}));
if( cli.path != "/" ){ cli.close(); return; }
cli.write( R"(
<!DOCTYPE html> <html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body style="transform: scaleY(-1);">
)" );
process::add( coroutine::add( COROUTINE(){
coBegin
while( true ){
cli.write( regex::format( NODEPP_STRINGIFY(
<h1 style="transform: scaleY(-1);">
Hello World! - ${0}
</h1>
) , process::now() ) );
coDelay(1000); }
coFinish
}));
});
server.onError([=]( except_t err ){
console::log( ">>", err.what() );
});
/*
server.listen( "[localhost]", 8000, [=]( socket_t server ){
console::log("server started at http://[::1]:8000");
});
*/
server.listen( "localhost", 8000, [=]( socket_t server ){
console::log("server started at http://localhost:8000");
});
}