Skip to content

Self-contained Example #10

@turbo

Description

@turbo

Hi,

A complete example of how to use this library would really help I think. I tried to set this up using lapis, but already failed at the config stage. Here's what I have so far:

app.moon

lapis = require "lapis"

rq = require "resty.qless"

ql = rq.new
  host: "127.0.0.1"
  port: 6379

class App extends lapis.Application    
  [index: "/"]: =>
    @html ->
      h1 "Hello!"
      p type ql

nginx.conf

worker_processes ${{NUM_WORKERS}};
error_log stderr notice;
daemon off;
pid logs/nginx.pid;

events {
  worker_connections 1024;
}

http {
  include mime.types;

  server {
    listen ${{PORT}};
    lua_code_cache ${{CODE_CACHE}};

    location / {
      default_type text/html;
      content_by_lua '
        require("lapis").serve("app")
      ';
    }

    location /static/ {
      alias static/;
    }

    location /favicon.ico {
      alias static/favicon.ico;
    }
  }
}

That's it. Running the app crashes in the route with this message:

2018/07/24 13:42:06 [error] 23077#23077: *1 lua entry thread aborted: runtime error: attempt to yield across C-call boundary
stack traceback:
coroutine 0:
        [C]: in function 'require'
        /usr/local/share/lua/5.1/lapis/init.lua:15: in function 'serve'
        content_by_lua(nginx.conf.compiled:22):2: in function <content_by_lua(nginx.conf.compiled:22):1>, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8080"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions