webform发布到服务器_用服务器端快速构建无服务器Webform

webform发布到服务器

Is it possible to implement a web site in Swift without using JavaScript? Yes, it is.

是否可以在不使用JavaScript的情况下在Swift中实现网站? 是的。

The trick is quite old and consists of generating the HTML page on the server. The idea is to avoid the use of JavaScript on the client, style the HTML with CSS, generate the pages with AWS Lambda, and serve the content with API Gateway. The persistency layer will be implemented with DynamoDB. We are going to use the Serverless framework to deploy our project on AWS.

技巧很老,包括在服务器上生成HTML页面。 这样做的目的是避免在客户端上使用JavaScript,使用CSS设置HTML样式,使用AWS Lambda生成页面,并使用API​​ Gateway提供内容。 持久性层将使用DynamoDB实现。 我们将使用无服务器框架在AWS上部署我们的项目。

无服务器项目设置 (Serverless Project Setup)

We’re assuming you have followed the readme to set up all the requirements:

我们假设您已经按照自述文件设置了所有要求:

  • AWS cli configured with your AWS account

    使用您的AWS账户配置的AWS CLI
  • Docker

    码头工人
  • Serverless

    无服务器
  • Make

    使

Clone the template project:

克隆模板项目:

git clone https://github.com/Andrea-Scuderi/aws-serverless-swift-sprinter-template.gitcd aws-serverless-swift-sprinter-template

Then build the project:

然后构建项目:

./build.sh
Image for post
./deploy.sh
Image for post

Once the project is deployed on your AWS account, the endpoint is created.

将项目部署到您的AWS账户后,便会创建终端节点。

Browse the generated URL with a web browser. The webform is up and running!

使用Web浏览器浏览生成的URL。 该网络表单已启动并正在运行!

Image for post

它是如何工作的? (How Does It Work?)

The Lambda provides a computational block in the AWS Serverless stack and interacts with DynamoDB to retrieve the data stored:

Lambda在AWS无服务器堆栈中提供了一个计算块,并与DynamoDB进行交互以检索存储的数据:

Image for post
Serverless cloud architecture
无服务器云架构

The HTML post content keeps track of the action sent from the browser and is translated by the Lambda to a CRUD (Create, Read, Update, Delete) command for DynamoDB.

HTML帖子内容跟踪从浏览器发送的操作,并由Lambda转换为DynamoDB的CRUD (创建,读取,更新,删除)命令。

After updating the DB, the content is presented in the response web page.

更新数据库后,内容将显示在响应网页中。

The API Gateway acts as a proxy publishing the Lambda content as a web server.

API网关充当将Lambda内容发布为Web服务器的代理。

The Serverless framework deploys the stacks to AWS.

无服务器框架将堆栈部署到AWS。

Swift中的Lambda (Lambda in Swift)

The Lambda is coded in Swift using the following frameworks:

Lambda使用以下框架在Swift中进行编码:

Image for post

The Lambda decodes the API Gateway proxy event and runs the WebController.

Lambda解码API网关代理事件并运行WebController。

The WebController updates DynamoDB with the information received and renders the next HTML page.

WebController使用收到的信息更新DynamoDB,并呈现下一个HTML页面。

The HTML page is returned as a response to the web client.

HTML页面作为对Web客户端的响应返回。

使用Plot渲染HTML (Using Plot to render the HTML)

The WebController renders the HTML passing the record list to the presenter, which is responsible for rendering the right web page.

WebController呈现将记录列表传递给演示者HTML,该演示者负责呈现正确的网页。

Image for post
Hello/Sources/WebController/Presenter.swift
你好/来源/WebController/Presenter.swift

The present function renders the main page with the content generated and evaluates the stateless action posted by the HTML client.

present的功能与渲染生成的内容的主页,发布评估由HTML客户端的无状态的作用。

Image for post
Image for post
Hello/Sources/WebController/Plot+Card.swift
你好/来源/WebController/Plot+Card.swift

The HTML is created by composing a small function implemented with the Plot framework. The picture above is an example of a card.

通过组合使用Plot框架实现的小功能来创建HTML。 上图是一张卡的示例。

将aws-sdk-swift用于DynamoDB (Using aws-sdk-swift for DynamoDB)

aws-sdk-swift is a Swift client for AWS and contains the client for DynamoDB. Here are some code snippets:

aws-sdk-swift是AWS的Swift客户端,包含DynamoDB的客户端。 以下是一些代码片段:

Image for post
Hello/Sources/ProductService/ProductService.swift
你好/来源/ProductService/ProductService.swift

结论 (Conclusion)

I hope to have generated some curiosity about server-side Swift and Swift-Sprinter.

我希望对服务器端Swift和Swift-Sprinter产生好奇。

Check out the GitHub repository and feel free to experiment. I look forward to seeing something nice!

查看GitHub存储库 ,随时尝试。 我期待看到美好的事物!

Thanks for reading.

谢谢阅读。

翻译自: https://medium.com/better-programming/build-a-serverless-webform-with-server-side-swift-8acaeedde216

webform发布到服务器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值