Xavante and simple function handler

44 views
Skip to first unread message

Jevito NC

unread,
Oct 6, 2014, 9:56:22 AM10/6/14
to kepler-...@googlegroups.com
Hi,

I would like to build an xavante application that call
- function1() on URI http://localhost:8080/call1
- function2() on URI http://localhost:8080/call2

I wrote this simple program that do not work

local xavante = require "xavante"
local filehandler = require "xavante.filehandler"
local wsx = require "wsapi.xavante"

-- Define here where Xavante HTTP documents scripts are located
local webDir = "/home/audibert/testXavante/xavante"

local simplerules = {
    {
      match = "call1",
      with = wsx.makeHandler(function1),
    },
    {
      match = "call2",
      with = wsx.makeHandler(function2),
    },
    { -- WSAPI application will be mounted under /app
      match = { "%.lua$", "%.lua/" },
      with = wsx.makeGenericHandler(webDir)
    },
    { -- filehandler
      match = ".",
      with = filehandler,
      params = {baseDir = webDir}
    },
}

function function1()
  print("Call 1")
end

function function2()
  print("Call 2")
end

-- Displays a message in the console with the used ports
xavante.start_message(function (ports)
    local date = os.date("[%Y-%m-%d %H:%M:%S]")
    print(string.format("%s Xavante started on port(s) %s",
      date, table.concat(ports, ", ")))
  end)

xavante.HTTP{
    server = {host = "*", port = 8080},

    defaultHost = {
        rules = simplerules
    },
}

function callback()
  print(os.date())
  return false
end

xavante.start()

How can I managed to register in simplerules the call of lua functions ?

Thank you very much.
Sincerely
Reply all
Reply to author
Forward
0 new messages