Serverless is a popular architecture in recent years. Through the Serverless function computing platform, you can focus on the core logic and run your code without purchasing and managing servers. In the Serverless mode, using the API Gateway can make the service available to external users, and realize advanced features such as security protection, traffic throttling, log monitoring, releasing in the cloud market, and automatic generation of SDK and documents.
Tencent Cloud API Gateway is highly integrated with Tencent Cloud SCF. This document describes how to build a website quickly by using the API Gateway as the entry to configure dynamic APIs through SCF and store static resources through COS.
With this method, you can use the API Gateway to make the Serverless service available quickly in the cloud.
Before building a website, you need to go to the API Gateway official repository to download the website source code, which contains a skeleton HTML file and static resources such as pictures, CSS files and JS files.
The directory structure of the downloaded file is as follows:
├── client // Root directory of the project
│ ├── static // Static resource
│ │ ├── background.jpg // Underground picture of the website
│ │ ├── favicon.ico // Website icon
│ │ ├── index.js // Script file
│ │ ├── style.css // Style file
│ ├── index.html // Website homepage
The SCF code used is as follows:
'use strict';
exports.main_handler = async(event, context, callback) => {
return {
data: 'hello world' // hello world can be replaced with any content
}
};
In addition to access the website you build through the default domain name provided by the API Gateway, you can also bind an custom domain name to the service. After binding, you can access the website through the custom domain name. For more information, see Configuring a Custom Domain Name.
Was this page helpful?