Permalink
Browse files

Add Kore (#224) (#430)

* Add Kore (#224)

* Use nginx rewrite module to support `/user/:id` path
  because this feature is still not supported so far
  (latest version: 3.1.0 at the moment)

* Update kore to use dynamic handler

* dismiss patch in version

* Update kore to free regex memory
  • Loading branch information...
zhangkaizhao authored and Marwan Rabbâa committed Oct 17, 2018
1 parent fbdaedb commit 760639336e1325960bdf52c611fd6ecbe7a417e7
Showing with 269 additions and 109 deletions.
  1. +1 −0 .travis.yml
  2. +4 −0 FRAMEWORKS.yml
  3. +111 −109 README.md
  4. +27 −0 c/kore/Dockerfile
  5. +5 −0 c/kore/hello/.gitignore
  6. +34 −0 c/kore/hello/conf/build.conf
  7. +10 −0 c/kore/hello/conf/hello.conf
  8. +67 −0 c/kore/hello/src/hello.c
  9. +10 −0 neph.yaml
View
@@ -62,6 +62,7 @@ env:
- FRAMEWORK=polka
- FRAMEWORK=rayo
- FRAMEWORK=turbo_polka
- FRAMEWORK=kore
script:
- shards build
View
@@ -179,3 +179,7 @@ java:
act:
website: actframework.org
version: "1.8"
c:
kore:
website: kore.io
version: "3.1"
View
220 README.md

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,27 @@
FROM ubuntu:18.04
RUN apt-get update -qq && \
apt-get install -qq -y \
wget \
make \
gcc \
openssl \
libssl-dev && \
apt-get clean -qq -y && \
apt-get autoclean -qq -y && \
apt-get autoremove -qq -y
RUN wget -c https://kore.io/releases/kore-3.1.0.tar.gz && tar xvf kore-3.1.0.tar.gz
RUN cd kore-3.1.0 && TASKS=1 NOTLS=1 make && make install
WORKDIR /usr/src/app
COPY hello hello
WORKDIR /usr/src/app/hello
RUN kodev build
EXPOSE 3000
CMD kore -f -n -r -c conf/hello.conf
View
@@ -0,0 +1,5 @@
*.o
.flavor
.objs
hello.so
assets.h
@@ -0,0 +1,34 @@
# hello build config
# You can switch flavors using: kodev flavor [newflavor]
# Set to yes if you wish to produce a single binary instead
# of a dynamic library. If you set this to yes you must also
# set kore_source together with kore_flavor.
#single_binary=no
#kore_source=/home/joris/src/kore
#kore_flavor=
# The flags below are shared between flavors
cflags=-Wall -Wmissing-declarations -Wshadow
cflags=-Wstrict-prototypes -Wmissing-prototypes
cflags=-Wpointer-arith -Wcast-qual -Wsign-compare
cxxflags=-Wall -Wmissing-declarations -Wshadow
cxxflags=-Wpointer-arith -Wcast-qual -Wsign-compare
# Mime types for assets served via the builtin asset_serve_*
#mime_add=txt:text/plain; charset=utf-8
#mime_add=png:image/png
#mime_add=html:text/html; charset=utf-8
dev {
# These flags are added to the shared ones when
# you build the "dev" flavor.
cflags=-g
cxxflags=-g
}
#prod {
# You can specify additional flags here which are only
# included if you build with the "prod" flavor.
#}
@@ -0,0 +1,10 @@
# hello configuration
bind 0.0.0.0 3000
load ./hello.so
domain * {
static / home
static /user user
dynamic ^/user/([^/]+)$ user_details
}
View
@@ -0,0 +1,67 @@
#include <kore/http.h>
#include <kore/kore.h>
int home(struct http_request *req);
int user(struct http_request *req);
int user_details(struct http_request *req);
int
home(struct http_request *req)
{
http_response(req, 200, NULL, 0);
return (KORE_RESULT_OK);
}
int
user(struct http_request *req)
{
http_response(req, 200, NULL, 0);
return (KORE_RESULT_OK);
}
int
user_details(struct http_request *req)
{
size_t nmatch = 2;
char *id;
struct kore_buf *buf;
regex_t re;
regmatch_t pmatch[nmatch];
buf = kore_buf_alloc(1024);
//kore_log(LOG_NOTICE, "path: %s", req->path);
//kore_log(LOG_NOTICE, "hdlr path: %s", req->hdlr->path);
if (regcomp(&re, req->hdlr->path, REG_EXTENDED)) {
kore_debug("regcomp() on %s failed", req->path);
kore_buf_free(buf);
regfree(&re);
return (KORE_RESULT_ERROR);
}
if (regexec(&re, req->path, nmatch, pmatch, 0) != 0) {
kore_debug("regexec() on %s failed", req->path);
kore_buf_free(buf);
regfree(&re);
return (KORE_RESULT_ERROR);
}
//id = strndup(req->path + pmatch[1].rm_so, pmatch[1].rm_eo - pmatch[1].rm_so);
unsigned int id_len = pmatch[1].rm_eo - pmatch[1].rm_so + 1;
id = kore_malloc(id_len);
kore_strlcpy(id, req->path + pmatch[1].rm_so, id_len);
kore_buf_appendf(buf, id);
http_response(req, 200, buf->data, buf->offset);
kore_buf_free(buf);
// Manually free `id` if `strndup` is used above.
//free(id);
regfree(&re);
return (KORE_RESULT_OK);
}
View
@@ -14,6 +14,7 @@ main:
- csharp
- java
- php
- c
crystal:
depends_on:
@@ -114,6 +115,10 @@ php:
- symfony
- laravel
c:
depends_on:
- kore
router.cr:
command: |
docker build -t router.cr .
@@ -398,3 +403,8 @@ laravel:
command: |
docker build -t laravel .
dir: php/laravel
kore:
command: |
docker build -t kore .
dir: c/kore

0 comments on commit 7606393

Please sign in to comment.