fastkiss

2025-12-07 0 340

fastkiss NIM的FastCGI网络框架

配x警告:这个框架仍处于重大发展。配x

Fastk eep i t s Mall和S Imple是NIM Web应用程序的FastCGI主机/服务器框架。它是针对NGINX开发的,但应与任何实现FCGI规格的Web服务器一起使用。这项工作基于NIM的FastCGI库。

FastCGI服务器允许您轻松地将fastkiss Web应用程序集成到标准的Web服务器环境中,利用为此目的开发的Web服务器提供的现有功能。这使您可以使用所有最先进的功能,例如高级协议支持(HTTPS,HTTP/2.0),HTTP保持稳定,高性能静态文件传递,HTTP压缩或URL REDIRECT/REWRITE服务,而无需增加在应用程序代码中构建任何内容的间接费用和复杂性。

fastkiss
from fastkiss /utils import decodeData
import regex
from strformat import `&`

proc main() =
let app = newApp()
app.config.port = 9000 # optional if default port

app.get(\”/\”, proc (req: Request) {.async.} =
respond \”Hello World!\”
)

app.get(r\”/test/(\\w+)\”.re, proc (req: Request) {.async.} =
respond &\”Hello {req.matches.groupCaptures(0)[0]}\”
)

# http://ex*ampl*e*:8080/test/abc-012/def-345/test/xpto
app.get(r\”/test/(?:([a-z\\d]+-[a-z\\d]+)/)+test/(\\w+)\”.re, proc (req: Request) {.async.} =
respond &\”Hello Multi Capture {$req.matches.groupCaptures(0)} and {$req.matches.groupCaptures(1)}\”
)

# http://exampl*e:8**080/myquery?a=1&b=2&c=3
app.get(\”/myquery\”, proc (req: Request) {.async.} =
resp \”My Query:\\n\”
for k, v in decodeData(req.url.query):
resp &\”{k} = {v}\\n\”
)

app.match([\”GET\”, \”POST\”], \”/method\”, proc (req: Request) {.async.} =
respond &\”Hello Method {$req.reqMethod}\”
)

app.get(\”/static\”, proc (req: Request) {.async.} =
sendFile \”./test.txt\”
)

app.run()

main()\”>

 import fastkiss
from fastkiss / utils import decodeData
import regex
from strformat import `&`

proc main() =
  let app = newApp()
  app.config.port = 9000 # optional if default port

  app.get( \" / \" , proc (req: Request) {.async.} =
    respond \" Hello World! \"
  )

  app.get( r \" /test/(\\w+) \" .re, proc (req: Request) {.async.} =
    respond & \" Hello { req.matches.groupCaptures( 0 )[ 0 ] } \"
  )

  # http://ex*ampl*e*:8080/test/abc-012/def-345/test/xpto
  app.get( r \" /test/(?:([a-z\\d]+-[a-z\\d]+)/)+test/(\\w+) \" .re, proc (req: Request) {.async.} =
    respond & \" Hello Multi Capture { $ req.matches.groupCaptures( 0 ) } and { $ req.matches.groupCaptures( 1 ) } \"
  )

  # http://exampl*e:8**080/myquery?a=1&b=2&c=3
  app.get( \" /myquery \" , proc (req: Request) {.async.} =
    resp \" My Query: \\n \"
    for k, v in decodeData(req.url.query):
      resp & \" { k } = { v } \\n \"
  )

  app.match([ \" GET \" , \" POST \" ], \" /method \" , proc (req: Request) {.async.} =
    respond & \" Hello Method { $ req.reqMethod } \"
  )

  app.get( \" /static \" , proc (req: Request) {.async.} =
    sendFile \" ./test.txt \"
  )

  app.run()

main()

如果您使用fastkiss生成具有显着尺寸的动态内容,例如大型二进制图像或大型基于文本的数据集,则需要考虑使用“ RESS ”功能而不是“响应”以最大程度地减少内存足迹并保持可伸缩性。

使用“ RESP ”功能使fastkiss无需构建整个结构或内存资源,将大量数据返回给客户端。请参见示例。您可以像php“ echo”功能一样使用“ RESP ”函数。您甚至可以以与PHP相同的方式包含具有代码的文件。请参阅此示例。

fastkiss
import tables
from strformat import `&`

proc showPage(req: Request) {.async.} =

let t = {1: \”one\”, 2: \”two\”, 3: \”three\”}.toTable

\”\”\”<!DOCTYPE html>
<html lang=\”en\”>
<head>
<meta charset=\”utf-8\”>
<meta name=\”viewport\” content=\”width=device-width\”>
<title>Test</title>
</head>
<body>
<table>\”\”\”.resp

for k, v in pairs(t):
resp &\”\”\”<tr>
<td><strong>{k}</strong></td>
<td>{v}</td>
</tr>
\”\”\”

\”\”\”</table>
</body>
</html>\”\”\”.resp

proc main() =
let app = newApp()
app.get(\”/\”, showPage)
app.run()

main()\”>

 import fastkiss
import tables
from strformat import `&`

proc showPage(req: Request) {.async.} =

  let t = { 1 : \" one \" , 2 : \" two \" , 3 : \" three \" }.toTable

  \"\"\" <!DOCTYPE html>
  <html lang=\"en\">
    <head>
      <meta charset=\"utf-8\">
      <meta name=\"viewport\" content=\"width=device-width\">
      <title>Test</title>
    </head>
    <body>
      <table> \"\"\" .resp

  for k, v in pairs(t):
    resp & \"\"\" <tr>
        <td><strong> { k } </strong></td>
        <td> { v } </td>
      </tr>
    \"\"\"

  \"\"\" </table>
    </body>
  </html> \"\"\" .resp

proc main() =
  let app = newApp()
  app.get( \" / \" , showPage)
  app.run()

main()

这是一个应用程序的完整示例,可以发送带有附件的电子邮件。

nginx fastcgi配置文件示例

 server {
  listen  8080;
  server_name example;
  # add example to hosts file
  # nano -w /etc/hosts
  #
  # 127.0.0.1   example
  #

  location / {
    # Comment this line if you if you don\'t need http cookies
    fastcgi_param HTTP_COOKIE $http_cookie;
    # Comment this line if you if you don\'t need Basic Autentication
    fastcgi_param HTTP_AUTHORIZATION $http_authorization;
    # Uses REMOTE_ADDR value whenever it needs to deal with visitor IP address.
    fastcgi_param REMOTE_ADDR $http_x_real_ip;

    client_max_body_size 1000M;
    include fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
  }
}

apache2 fastcgi配置文件示例

 Listen 127.0.0.1:8080
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule rewrite_module modules/mod_rewrite.so
# Need a server with SSL support
# LoadModule http2_module modules/mod_http2.so

<IfModule mod_proxy_fcgi.c>
<VirtualHost *:8080>
  ServerName example
  ServerAlias anotherexample
  ServerAdmin admin@example.tld

  ErrorLog /var/log/httpd/example_error.log
  CustomLog /var/log/httpd/example_requests.log combined

  ProxyPass \"/\" \"fcgi://localhost:9000/\"

  # https://httpd.*apa**che.org/docs/2.4/custom-error.html
  ErrorDocument 503 \"Service Temporary Unavailable\"

  # Need a server with SSL support
  # Protocols h2 http/1.1

  # Comment this two lines below if you if you don\'t need Basic Autentication
  RewriteEngine on
  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</VirtualHost>
</IfModule>

测试

 $ nimble install https://**github.c*om/mrhdias/fastkiss
$ nano -w example.nim
$ nim c -r example.nim
$ sudo systemctl start nginx / httpd
$ wget -qO- http://*exa*mp*le:8080/test
Hello World!!⏎

编译发布版本使用:

 $ nim c -d:release example.nim
$ ./example

配置选项

config.port = 9000 # Default Port
config.address = \" \"
config.reuseAddr = true # Default value
config.reusePort = false # Default value

# Default temporary directory of the current user to save temporary files
config.tmpUploadDir = getTempDir()
# The value true will cause the temporary files left after request processing to be removed.
config.autoCleanTmpUploadDir = true
# To serve static files such as images, CSS files, and JavaScript files
config.staticDir = \" \"
# Sets the maximum allowed size of the client request body
config.maxBody = 8388608 # Default 8MB = 8388608 Bytes

可用的路由器方法

响应任何HTTP动词的路线

get * (
  server: AsyncFCGIServer,
  pattern: string | Regex,
  callback: proc (request: Request): Future[ void ] {.closure, gcsafe.}
)

post * (
  server: AsyncFCGIServer,
  pattern: string | Regex,
  callback: proc (request: Request): Future[ void ] {.closure, gcsafe.}
)

put * (
  server: AsyncFCGIServer,
  pattern: string | Regex,
  callback: proc (request: Request): Future[ void ] {.closure, gcsafe.}
)

patch * (
  server: AsyncFCGIServer,
  pattern: string | Regex,
  callback: proc (request: Request): Future[ void ] {.closure, gcsafe.}
)

delete * (
  server: AsyncFCGIServer,
  pattern: string | Regex,
  callback: proc (request: Request): Future[ void ] {.closure, gcsafe.}
)

options * (
  server: AsyncFCGIServer,
  pattern: string | Regex,
  callback: proc (request: Request): Future[ void ] {.closure, gcsafe.}
)

响应多个HTTP动词的路线

match * (
  server: AsyncFCGIServer,
  methods: openArray [ string ],
  pattern: string | Regex,
  callback: proc (request: Request): Future[ void ] {.closure, gcsafe.}
)

响应所有HTTP动词的路线

 any * (
  server: AsyncFCGIServer,
  pattern: string | Regex,
  callback: proc (request: Request): Future[ void ] {.closure, gcsafe.}
)

下载源码

通过命令行克隆项目:

git clone https://github.com/mrhdias/fastkiss.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 开发教程 fastkiss https://www.zuozi.net/31885.html

libredte lib core
上一篇: libredte lib core
RabbitServer
下一篇: RabbitServer
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务