-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog.cpp
67 lines (55 loc) · 1.59 KB
/
blog.cpp
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
#include <stdio.h>
#include <iostream>
#include "requesthandler.hpp"
#include "responsehandler.hpp"
#include "common.hpp"
#include "functional/either.hpp"
#include "templateengine.hpp"
#include "sqlworker.hpp"
#include "mysqlworker.hpp"
#include "orm/orm.hpp"
class BlogPost
{
public:
BlogPost()
{
}
void initOrm(orm::OrmFieldHandler handler)
{
handler << ORM_MODEL_FIELD(postCaption);
handler << ORM_MODEL_FIELD(postText);
}
std::string postCaption;
std::string postText;
};
ORM_EXPORT_CLASS(BlogPost);
int main(int argc, char **argv)
{
std::string pathToExe = pathToFile(argv[0]);
std::string exeName = last(split(argv[0], '/'));
MySQLWorker mysql;
mysql.connect("192.168.10.101", "root", "123", "blogDB");
orm::Database db(&mysql);
db.registerModel<BlogPost>();
if(argc > 1){
std::cout << "Migrate" << std::endl;
db.createScheme();
return 0;
}
cgi::RequestHandler request;
cgi::ResponseHandler response;
cgi::RequestArgs args = request.getArgs();
cgi::RequestArgs cont;
cont["STATIC_PATH"] = exeName + "?staticfile=";
if (args.count("staticfile")){
std::string reqFile = args["staticfile"];
std::string res = readFile(std::string("../static/") + reqFile);
if(getExtensionOfFileByPath(reqFile) == "js")
response.mimeType = "text/javascript";
response << res;
}else{
response << cgi::TemplateEngine::renderTemplate(readFile(pathToExe + "../templates/blogindex.html"), cont).getValue();
}
response.send();
return 1;
}