-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
209 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
name: Publish Docker Images | ||
on: | ||
push: | ||
branches: ['main'] | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
push-image: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
#include <ctorm/ctorm.h> | ||
#include <ctorm/macros.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
void hello_world(req_t* req, res_t* res){ | ||
res_send(res, "hello world!"); | ||
RES_SEND("hello world!"); | ||
} | ||
|
||
int main(){ | ||
log_set(false); | ||
app_init(); | ||
app_t *app = app_new(); | ||
|
||
GET("/", hello_world); | ||
app_run("127.0.0.1:8080"); | ||
APP_RUN("127.0.0.1:8080"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
#include "../include/ctorm.h" | ||
#include "../include/macros.h" | ||
|
||
void handle_notfound(req_t *req, res_t *res) { | ||
res->code = 404; | ||
res_sendfile(res, "./example/404.html"); | ||
RES_SENDFILE("./example/404.html"); | ||
} | ||
|
||
void handle_post(req_t *req, res_t *res) { | ||
body_t *body = req_body_parse(req); | ||
if (NULL == body) | ||
return res_send(res, "bad body"); | ||
return RES_SEND("bad body"); | ||
|
||
char *msg = req_body_get(body, "msg"); | ||
if (NULL == msg) | ||
return res_send(res, "bad body"); | ||
return RES_SEND("bad body"); | ||
|
||
res_render_add(res, "msg", msg); | ||
res_render(res, "./example/template/post.html"); | ||
RES_RENDER_ADD("msg", msg); | ||
RES_RENDER("./example/template/post.html"); | ||
|
||
info("Message: %s", msg); | ||
res_set(res, "Cool", "yes"); | ||
RES_SET("Cool", "yes"); | ||
req_body_free(body); | ||
} | ||
|
||
void handle_get(req_t *req, res_t *res) { | ||
res_render(res, "./example/template/index.html"); | ||
RES_RENDER("./example/template/index.html"); | ||
} | ||
|
||
int main() { | ||
app_init(); | ||
app_t *app = app_new(); | ||
|
||
GET("/", handle_get); | ||
POST("/post", handle_post); | ||
|
||
app_static("/static", "./example/static"); | ||
app_all(handle_notfound); | ||
APP_STATIC("/static", "./example/static"); | ||
APP_ALL(handle_notfound); | ||
|
||
if (!app_run("0.0.0.0:8080")) | ||
if (!APP_RUN("0.0.0.0:8080")) | ||
error("app failed: %s\n", geterror()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include "ctorm.h" | ||
|
||
#define APP_RUN(host) app_run(app, host) | ||
#define APP_ALL(route) app_all(app, route) | ||
#define APP_STATIC(path, dir) app_static(app, path, dir) | ||
|
||
#define REQ_HEADER(header) req_header(req, header) | ||
#define REQ_QUERY(query) req_query(req, query) | ||
|
||
#define RES_SEND(text) res_send(res, text) | ||
#define RES_SENDFILE(path) res_sendfile(res, path) | ||
#define RES_SET(header, value) res_set(res, header, value) | ||
|
||
#define RES_RENDER_ADD(key, value) res_render_add(res, key, value) | ||
#define RES_RENDER(path) res_render(res, path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.