No description
Find a file
2021-10-01 07:41:36 +07:00
.github Create FUNDING.yml 2021-10-01 07:41:36 +07:00
docs make them all templates, and update README 2019-09-26 00:04:09 +07:00
src fix indent 2019-10-15 14:38:38 +07:00
tests upgrade version 3.2.1 2019-10-15 07:36:07 +00:00
LICENSE Initial commit 2018-10-16 13:05:24 +07:00
ngxcmod.nimble make them all templates, and update README 2019-09-26 00:04:09 +07:00
README.md Update README, closes #2 2019-10-30 07:37:59 +07:00

ngxcmod

This module contains high level API definations to build module for Nginx with nginx-link-function

For low level API, please import ngxcmod/raw

Requirements

Usage

Nim module

import ngxcmod, strutils

proc init(ctx: ContextCycle) {.init.} =
  ctx.cyc_log(INFO, "hello from Nim")

proc exit(ctx: ContextCycle) {.exit.} =
  ctx.cyc_log(WARN, "goodbye, from Nim w/ <3")

proc hello(ctx: Context) {.exportc.} =
  ctx.log(INFO, "Calling back and log from hello")
  let
    name = ctx.getQueryParam("name")
    message = "hello $#, greeting from Nim" % name
  ctx.response(200, "200 OK", CONTENT_TYPE_PLAINTEXT, message)

proc post(ctx: Context) {.exportc.} =
  ctx.response(200, "200 OK", CONTENT_TYPE_PLAINTEXT, ctx.getBodyAsStr())

Nginx config

http {
...
    server {
...
        ngx_link_func_lib "./your-module.so";
        location = /hello {
            ngx_link_func_call "hello";
        }
...
}