Posted on 2015-01-06
Kore是用c写的超快速和灵活的Web服务器/框架,作者Joris Vink, 今天在github上找到,准备用来练习一下c语言
$ git clone https://github.com/jorisvink/kore.git
$ cd kore
$ make
$ sudo make install
$ kore create myapp
此时工程的目录:
$ cd myapp
$ kore build
$ kore run
通过浏览器查看https://127.0.0.1:8888/,可以看见一个空白页面
修改myapp.c
#include <kore/kore.h>
#include <kore/http.h>
#include "assets.h"
int page(struct http_request *);
int
page(struct http_request *req)
{
http_response_header(req, "content-type", "text/html");
http_response(req, 200, asset_index_html, asset_len_index_html);
return (KORE_RESULT_OK);
}
在assets文件夹下添加index.html
<!DOCTYPE>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
Hello World!
</body>
</html>
编译运行
$ kore build
$ kore run
通过浏览器查看https://127.0.0.1:8888/,看见Hello World!