Cloudflare 通过 CloudflareWorkers 提供无服务器计算服务,后者是用于构建和部署在 Cloudflare 边缘网络上运行的JavaScript函数的平台。在边缘(尽可能靠近最终用户)运行代码有助于减少延迟并提高应用程序性能。每个 Worker 都可以修改并响应HTTP请求。
Blueboat就是CloudflareWorkers的开源替代品,旨在成为无服务器Web应用开发者友好的多租户平台。
一个简单的Blueboat应用程序如下所示:Router.get("/",req=>ewRespose("helloworld"));Router.get("/example",req=>{returfetch("https://example.com");});Router.get("/yaml",req=>{costres=TextUtil.Yaml.strigify({hello:"world",});returewRespose(res);});使用托管服务的快速入门安装 bbcli对于Liux:curl-sSL-o/tmp/bbcli.tar.gzhttps://github.com/losfair/bbcli/releases/dowload/v0.1.0-alpha.1/bbcli_liux.tar.gztar-xzvf/tmp/bbcli。tar.gz-C~chmod+x~/bbcli&&rm/tmp/bbcli.tar.gz对于macOS:curl-sSL-o/tmp/bbcli.tar.gzhttps://github.com/losfair/bbcli/releases/dowload/v0.1.0-alpha.1/bbcli_macos.tar.gztar-xzvf/tmp/bbcli。tar.gz-C~chmod+x~/bbcli&&rm/tmp/bbcli.tar.gz克隆示例项目gitcloehttps://github.com/losfair/blueboat-examples部署项目cdblueboat-examples/hello-worldpmi~/bbclideploy--vars./hosted.vars.yaml部署Blueboat实例先决条件Docker用于存储应用程序配置和代码的S3兼容bucket用于存储 bbcp 元数据的MySQL服务(可选)用于流式传输日志的Kafka服务部署示例:versio:"3"services:blueboat:image:ghcr.io/losfair/blueboat:latestuser:daemoports:-"127.0.0.1:3000:3000"etrypoit:-/usr/bi/blueboat_server--l-0.0.0.0:3000---s3-bucket-my-bucket.example.com---s3-regio-us-east-1#Ucommetthisifyouuseao-AWSS3-compatibleservice.#---s3-edpoit#-https://miio.example.com#UcommetthistoeableloggigtoKafka.#---log-kafka#-et.uivalet.blueboat-log.default:0@kafka:9092#Ucommetthistoeablegeoipiformatioithe`x-blueboat-cliet-coutry`,#`x-blueboat-cliet-city`,`x-blueboat-cliet-subdivisio-1`ad#`x-blueboat-cliet-subdivisio-2`requestheaders.#---mmdb-city#-/opt/blueboat/mmdb/GeoLite2-City.mmdb#UcommetthistoeableautomaticWikipediaIPblocklistqueryithe#`x-blueboat-cliet-wpbl`requestheader.#Thedatabaseisgeeratedwithhttps://github.com/losfair/wpblsyc.#---wpbl-db#-/opt/blueboat/wpbl/wpbl.dbeviromet:RUST_LOG:ifoAWS_ACCESS_KEY_ID:your_s3_access_key_idAWS_SECRET_ACCESS_KEY:your_s3_secret_access_key#Ucommetthistoeabletextrederigicavas.#SMRAPP_BLUEBOAT_FONT_DIR:/opt/blueboat/fots
评论