requirement :
- redis
- nginx
- lua
snippets nginx
access_by_lua_block {
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000) -- 1 sec
local ok, err = red:connect("127.0.0.1", 6379,"pool_size=128")
if not ok then
ngx.exit(503)
return
end
local key = ngx.var.uri
local method = ngx.var.request_method
if method == "POST" or method == "PUT" then
-- local set value = ngx
ngx.req.read_body()
local data = ngx.req.get_body_data()
red:set(key,data)
ngx.say("ok")
return
end
if method == "GET" then
local res, err = red:get(key)
if res ~= ngx.null then
-- ngx.redirect(res, 301)
ngx.header["Content-type"] = "text/plain; charset=UTF-8"
ngx.say(res)
return
end
end
if method == "DELETE" then
red:del(key)
ngx.say("deleted")
-- return
end
}
location nginx
location / {
include /etc/nginx/snippets/api.lua;
try_files $uri $uri/ =404;
}
redis.lua
from https://github.com/openresty/lua-resty-redis/releases
and
lua_package_path "/etc/nginx/lib/redis.lua;;";
client post
post
file :
#!/bin/bash
lol=$(cat)
id=$(openssl rand -hex 7)
echo "$lol" |curl -qs -X POST --data-binary @- -o /dev/null http://localhost/paste/$id
echo "http://localhost/paste/$id"
example :
$ echo hello | post
http://localhost/paste/cdc89098c8f24e