cuid 是一个不错的id 生成算发,类似的有shortid 、hashid
演示使用lua 包集成openresty 做测试

使用docker-compose 运行

dockerfile

FROM openresty/openresty:alpine-fat
RUN apk add --no-cache curl perl
RUN /usr/local/openresty/luajit/bin/luarocks install cuid
EXPOSE 80
COPY nginx.conf usr/local/openresty/nginx/conf/

docker-compose file

version: "3"
services:
id:
build: .
image: dalongrong/cuid-openresty
ports:
- "8080:80"

nginx.conf

worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root html;
index index.html index.htm;
}
location /id {
default_type text/html;
content_by_lua_block {
local cuid = require("cuid")
local id = cuid.generate ( )
local slug = cuid.slug ( )
ngx.say("<div> shortid "..slug.."</div>".."<div>long id"..id.."</div>")
}
}
location /alert {
default_type text/html;
content_by_lua_block{
ngx.say([[<script>alert("error")</script>]])
}
}
location /ip {
default_type text/html;
content_by_lua_block{
ngx.say(ngx.var.remote_addr)
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

构建&&运行

  • 构建
docker-compose build
  • 运行
docker-compose up -d
  • 访问
open http://localhost:8080/id
  • 效果

参考资料

https://hub.docker.com/r/openresty/openresty/
https://github.com/rongfengliang/openresty-cuid-demo
https://github.com/marcoonroad/cuid
https://www.npmjs.com/package/cuid

 
 
 
 

最新文章

  1. JDBC的一些基础提交语句回顾
  2. iOS所有的子视图
  3. UsefulSQL
  4. python print输出unicode字符
  5. The web application [] appears to have started a thread named [Abandoned connection cleanup thread] com.mysql.jdbc.AbandonedConnectionCleanupThread
  6. Asp.NET MVC JSON序列化问题
  7. C#130问,初级程序员的面试宝典
  8. ListView Animation
  9. System.Data.OracleClient requires Oracle client software version 8.1.7 or greater
  10. FZU 1753
  11. Codeforces 294E Shaass the Great
  12. 关于jQuery表单校验的应用
  13. NAS4Free 配置BT下载
  14. 创建 Mac OS X 10.9 USB 安装盘
  15. C#实现谷歌翻译API
  16. MyBatis --- 动态SQL、缓存机制
  17. [翻译] 编写高性能 .NET 代码--第二章 GC -- 配置选项
  18. Python: datetime 转换
  19. perl trick
  20. HTML 圆心节点

热门文章

  1. 20170814xlVBA部分代号收盘价转置
  2. React 介绍
  3. Confluence 6 使用 LDAP 授权连接一个内部目录概述
  4. 让CLOVER默认引导WINDOWS
  5. 微信小程序自定义模态框(字体图标)
  6. 使用tomcat启动dubbo项目
  7. PHP:第三章——数组中的array_values
  8. HDU 3226 背包
  9. Java多线程安全问题
  10. MyEclipse持续性开发教程:用JPA和Spring管理数据(三)