Kore简单介绍

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

此时工程的目录:

  • myapp +
    • src(源码) +
      • myapp.c
    • conf(配置文件) +
      • myapp.conf
    • cert(证书文件) +
      • server.crt
      • server.key
    • assets(页面,css,图片等)

编译运行

$ cd myapp
$ kore build
$ kore run

通过浏览器查看https://127.0.0.1:8888/,可以看见一个空白页面

Hello World

修改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!