-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
executable file
·42 lines (31 loc) · 1.01 KB
/
server.lua
File metadata and controls
executable file
·42 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env tarantool
local json = require('json')
local handler = require('handler')
local conf = require('config')
box.cfg{
listen = conf.listen,
log_format = conf.log_format,
log = conf.log_file,
background = conf.back,
pid_file = conf.pid
}
box.once('init', function()
box.schema.create_space('dict')
box.space.dict:create_index(
'primary', {type = 'hash', parts = {1, 'string'}})
end)
local http_router = require('http.router')
local http_server = require('http.server')
local server = http_server.new(
nil,conf.port, { log_requests = true, log_errors = true })
local router = http_router.new()
router:route({
path = handler.path_get, method = 'GET'}, handler.get_method)
router:route({
path = handler.path_post, method = 'POST'}, handler.post_method)
router:route({
path = handler.path_put, method = 'PUT'}, handler.put_method)
router:route({
path = handler.path_delete, method = 'DELETE'}, handler.delete_method)
server:set_router(router)
server:start()