httpd:route doesn't work
cptLamo opened this issue · 4 comments
cptLamo commented
Hello, i try to run http server on tarantool, but when i need to run route, it return me error.
- error: '[string "return httpd:route( { path = ''/metrics'' }, pr..."]:1: attempt
to call method ''route'' (a nil value)
Any advice?
Thank you.
olegrok commented
Hello, thank you for a question I assume that it's a quite frequent question
It was changed in v2+
local httpd = http_server.new(HOST, PORT)
local router = http_router.new()
:route({ path = '/format', method = 'GET' }, handler)
httpd:set_router(router)
httpd:start()
Use fixed old version (especially not scm) or update your code
D-Y-V commented
This work.
Create module /usr/local/share/tarantool/site.lua
----------------------------BOF
local site = {}
--local function private()
-- print("in private function")
--end
function site.index(req)
return {
status = 200,
headers = { ['content-type'] = 'text/html; charset=utf8' },
body = [[
<html>
<body>Hello, world!</body>
</html>
]]
}
end
--function site.bar()
-- private()
-- site.foo() -- need to prefix function call with module
--end
return site
-----------------------------EOF
Connect to server. In console do:
srv1 = require('http.server').new('0.0.0.0', 8080)
router = require('http.router').new({charset = "utf8"})
srv1:set_router(router)
router:route({
path = '/',
name = 'index',
method = 'GET',
}, 'site#index')
srv1:start()
D-Y-V commented
Yes19 мая 2021 г. 08:09 пользователь Primadi Setiawan ***@***.***> написал:
router = require('http.router').new()
in log:
Start failed: /usr/share/tarantool/main.lua:6: module 'http.router' not found:
no field package.preload['http.router']
no file '/opt/tarantool/http/router.lua'
no file '/opt/tarantool/http/router/init.lua'
no file '/opt/tarantool/http/router.so'
no file '/opt/tarantool/.rocks/share/tarantool/http/router.lua'
no file '/opt/tarantool/.rocks/share/tarantool/http/router/init.lua'
no file '/opt/.rocks/share/tarantool/http/router.lua'
no file '/opt/.rocks/share/tarantool/http/router/init.lua'
no file '/.rocks/share/tarantool/http/router.lua'
no file '/.rocks/share/tarantool/http/router/init.lua'
no file '/opt/tarantool/.rocks/lib/tarantool/http/router.so'
no file '/opt/.rocks/lib/tarantool/http/router.so'
no file '/.rocks/lib/tarantool/http/router.so'
no file '/root/.luarocks/share/lua/5.1/http/router.lua'
no file '/root/.luarocks/share/lua/5.1/http/router/init.lua'
no file '/root/.luarocks/share/lua/http/router.lua'
no file '/root/.luarocks/share/lua/http/router/init.lua'
no file '/usr/local/share/tarantool/http/router.lua'
no file '/usr/local/share/tarantool/http/router/init.lua'
no file '/usr/share/tarantool/http/router.lua'
no file '/usr/share/tarantool/http/router/init.lua'
no file '/usr/local/share/lua/5.1/http/router.lua'
no file '/usr/local/share/lua/5.1/http/router/init.lua'
no file '/usr/share/lua/5.1/http/router.lua'
no file '/usr/share/lua/5.1/http/router/init.lua'
no file '/root/.luarocks/lib/lua/5.1/http/router.so'
no file '/root/.luarocks/lib/lua/http/router.so'
no file '/usr/local/lib64/tarantool/http/router.so'
no file '/usr/local/lib/tarantool/http/router.so'
no file '/usr/lib64/tarantool/http/router.so'
no file '/usr/local/lib64/lua/5.1/http/router.so'
no file '/usr/local/lib/lua/5.1/http/router.so'
no file '/usr/lib64/lua/5.1/http/router.so'
no file '/root/.luarocks/lib/lua/5.1/http.so'
no file '/root/.luarocks/lib/lua/http.so'
no file '/usr/local/lib64/tarantool/http.so'
no file '/usr/local/lib/tarantool/http.so'
no file '/usr/lib64/tarantool/http.so'
no file '/usr/local/lib64/lua/5.1/http.so'
no file '/usr/local/lib/lua/5.1/http.so'
no file '/usr/lib64/lua/5.1/http.so'
no file '/usr/local/lib/lua/5.1/http/router.so'
no file '/usr/lib64/lua/5.1/http/router.so'
no file '/root/.luarocks/lib/lua/5.1/http.so'
no file '/root/.luarocks/lib/lua/http.so'
no file '/usr/local/lib64/tarantool/http.so'
no file '/usr/local/lib/tarantool/http.so'
no file '/usr/lib64/tarantool/http.so'
no file '/usr/local/lib64/lua/5.1/http.so'
no file '/usr/local/lib/lua/5.1/http.so'
no file '/usr/lib64/lua/5.1/http.so'
is http.router module now changed ?
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or unsubscribe.
Totktonada commented
We discarded http v2. See details in #134 and https://github.com/tarantool/http/releases/tag/1.1.1.