基于serverless快速部署前端项目到腾讯云

腾讯云 COS 组件,可以快速部署静态网站页面到对象存储 COS 中,并生成域名供访问。
安装
首先要安装 serverless 组件
npm install -g serverless
在项目的根目录下生成配置文件
touch serverless.yml
<a name="YpT8f"></a>
配置
在 serverless.yml 文件中进行如下配置
# serverless.yml
myWebsite:
component: '@serverless/tencent-website'
inputs:
code:
src: build
hook: npm run build
index: index.html
error: index.html
region: ap-guangzhou
bucketName: my-bucket
部署
如您的账号未登陆或注册腾讯云,您可以直接通过 微信 扫描命令行中的二维码进行授权登陆和注册。
通过 sls 命令进行部署,并可以添加 --debug 参数查看部署过程中的信息(对于Windows用户来说, sls 命令可能无法使用,在使用时需要使用完整的 serverless 命令)
$ sls --debug
DEBUG ─ Resolving the template's static variables.
DEBUG ─ Collecting components from the template.
DEBUG ─ Downloading any NPM components found in the template.
DEBUG ─ Analyzing the template's components dependencies.
DEBUG ─ Creating the template's components graph.
DEBUG ─ Syncing template state.
DEBUG ─ Executing the template's components graph.
DEBUG ─ Starting Website Component.
DEBUG ─ Preparing website Tencent COS bucket my-bucket-1300415943.
DEBUG ─ Deploying "my-bucket-1300415943" bucket in the "ap-guangzhou" region.
DEBUG ─ "my-bucket-1300415943" bucket was successfully deployed to the "ap-guangzhou" region.
DEBUG ─ Setting ACL for "my-bucket-1300415943" bucket in the "ap-guangzhou" region.
DEBUG ─ Ensuring no CORS are set for "my-bucket-1300415943" bucket in the "ap-guangzhou" region.
DEBUG ─ Ensuring no Tags are set for "my-bucket-1300415943" bucket in the "ap-guangzhou" region.
DEBUG ─ Configuring bucket my-bucket-1300415943 for website hosting.
DEBUG ─ Uploading website files from /Users/dfounderliu/Desktop/temp/code/src to bucket my-bucket-1300415943.
DEBUG ─ Starting upload to bucket my-bucket-1300415943 in region ap-guangzhou
DEBUG ─ Uploading directory /Users/dfounderliu/Desktop/temp/code/src to bucket my-bucket-1300415943
DEBUG ─ Website deployed successfully to URL: https://my-bucket-1300415943.cos-website.ap-guangzhou.myqcloud.com.
myWebsite:
url: https://my-bucket-1300415943.cos-website.ap-guangzhou.myqcloud.com
env:
2s › myWebsite › done
移除
通过以下命令移除项目
$ sls remove --debug
DEBUG ─ Flushing template state and removing all components.
DEBUG ─ Starting Website Removal.
DEBUG ─ Removing Website bucket.
DEBUG ─ Removing files from the "my-bucket-1300415943" bucket.
DEBUG ─ Removing "my-bucket-1300415943" bucket from the "ap-guangzhou" region.
DEBUG ─ "my-bucket-1300415943" bucket was successfully removed from the "ap-guangzhou" region.
DEBUG ─ Finished Website Removal.
3s › myWebsite › done
账号配置(可选)
当前默认支持 CLI 扫描二维码登录,如您希望配置持久的环境变量/秘钥信息,也可以本地创建 .env 文件
$ touch .env # 腾讯云的配置信息
在 .env 文件中配置腾讯云的 SecretId 和 SecretKey 信息并保存<br />
如果没有腾讯云账号,可以在此注册新账号。
如果已有腾讯云账号,可以在API 密钥管理中获取 SecretId 和SecretKey.
# .env
TENCENT_SECRET_ID=123
TENCENT_SECRET_KEY=123
配置文件详解
一个完整的配置文件如下所示
myWebsite:
component: '@serverless/tencent-website'
inputs:
code:
root: ./
src: ./src
hook: npm run build
index: index.html
error: index.html
region: ap-guangzhou
bucketName: my-bucket
protocol: http
hosts:
- host: abc.cn
- host: abc.com
fullUrl: on
cache:
- type: 0
rule: all
time: 1000
- type: 0
rule: all
time: 1000
cacheMode: simple
refer:
- type: 1
list:
- 'qq.baidu.com'
- '*.baidu.com'
accessIp:
type: 1
list:
- '1.2.3.4'
- '2.3.4.5'
https:
certId: 123
cert: 123
privateKey: 123
http2: off
httpsType: 2
forceSwitch: -2
env:
API_URL: https://api.com
cors:
- allowedOrigins:
- '*.tencent.com'
- '*.qcloud.com'
allowedMethods:
- PUT
- POST
- DELETE
- HEAD
allowedHeaders: '*'
maxAgeSeconds: 0
- allowedOrigins:
- '*'
allowedMethods:
- GET
allowedHeaders: '*'
maxAgeSeconds: 0
主要参数说明
| 参数 | 必须/可选 | 默认 | 描述 |
|---|---|---|---|
| code | 必须 | 网站代码信息 | |
| region | 可选 | ap-guangzhou | 存储桶所属地域,默认为广州 |
| bucketName | 必须 | 存储桶名称,如果您不添加AppId后缀,则会自动为您添加,后缀不能大写 | |
| protocol | 可选 | https | 协议:https 或者 http |
| env | Optional | Environment variables to include in a 'env.js' file with your uploaded code. | |
| cors | Optional | Cross-Origin Resource Sharing | |
| hosts | Optional | Add domain |
代码参数说明
| 参数 | 必须/可选 | 默认 | 描述 |
|---|---|---|---|
| root | 可选 | 您的网站项目的根文件夹。 默认为当前工作目录 | |
| src | 必须 | 包含您构建的工件的要上传的文件夹 | |
| hook | 可选 | 在上传之前对代码进行构建/测试/执行任何操作的钩子 | |
| index | 可选 | index.html | 索引页 |
| error | 可选 | error.html | 错误页面_(对于使用前端框架构建的应用程序来说,需要将此参数设置为索引页,否则在页面刷新或重定向是会出现问题)_ |
来源:安徽网站优化
基于serverless快速部署前端项目到腾讯云的更多相关文章
- 部署Flask项目到腾讯云服务器CentOS7
部署Flask项目到腾讯云服务器CentOS7 安装git yum install git 安装依赖包 支持SSL传输协议 解压功能 C语言解析XML文档的 安装gdbm数据库 实现自动补全功能 sq ...
- 基于云原生DevOps服务自动化部署前端项目学习总结
本文主要以部署前端Vue项目为例,讲述了如何基于云原生DevOps服务自动化部署前端项目~从开发完成到线上环境,我们只需提交代码即可~ 一.引言 作为一名开发人员,日常工作中我们除了需要负责代码的开发 ...
- 使用vue2.x+webpack+vuex+sass+axios+elementUI等快速搭建前端项目框架
一.本文将分享如何快速搭起基于webpack+vue的前端项目框架,利用vue的自己的脚手架工具vue-cli搭建起基本的环境配置,再通过npm包管理工具引入相应的依赖来完善项目的各种依赖框架.下面是 ...
- 记基于docker+gunicorn部署sanic项目遇到的很多很多坑
前言: 最近有个项目需要上线,是python中sanic网络异步框架写的,并且要求使用docker+nginx来部署项目实现负载均衡,于是乎百度了sanic项目部署,基本上都是基于docker+gun ...
- docker自动化部署前端项目实战一
docker自动化部署前端项目实战一 本文适用于个人项目,如博客.静态文档,不涉及后台数据交互,以部署文档为例. 思路 利用服务器node脚本,监听github仓库webhook push事件触发po ...
- 在基于ABP框架的前端项目Vue&Element项目中采用电子签名的处理
在前面随笔介绍了<在基于ABP框架的前端项目Vue&Element项目中采用电子签章处理文件和打印处理>的处理,有的时候,我们在流程中或者一些文件签署的时候,需要签上自己的大名,一 ...
- Tomcat+Nginx+Linux+Mysql部署豆瓣TOP250的项目到腾讯云服务器
写在前面 因为前面有写过一篇关于豆瓣的top250的电影的可视化展示项目,你可以移步http://blog.csdn.net/liuge36/article/details/78607955了解这个项 ...
- 在基于ABP框架的前端项目Vue&Element项目中采用电子签章处理文件和打印处理
在一些内部OA或者流转的文件,或者给一些客户的报价文件.合同,或者一些医院出示的给保险机构的病历资料等,有时候可能都希望快速的使用电子签章的处理方式来给文件盖上特定的印章,本篇随笔介绍基于Vue&am ...
- 简单的利用nginx部署前端项目
网上有很多教程写的一大堆东西,新手可能会有点看不懂,现在我写这篇文章是为了更好的帮助新手,如何将自己的前端项目部署到自己的服务器上. 首先我们必须要有一台自己的ubuntu服务器,如果没有可以去阿里云 ...
随机推荐
- js interval ,timeout
var inter; intervatest("2019-08-22 09:12:00"); function intervatest(str) { ShowCountDown(s ...
- yarn storm spark
单机zookeeper http://coolxing.iteye.com/blog/1871009 storm http://os.51cto.com/art/201309/411003_2.htm ...
- mysql第四篇:数据操作之多表查询
mysql第四篇:数据操作之多表查询 一.多表联合查询 #创建部门 CREATE TABLE IF NOT EXISTS dept ( did int not null auto_increment ...
- VUE.js入门学习(4)-动画特效
1.VUE中CSS动画原理(more是 v-enter 具体的根据 name的来决定) 动画是通过在某一时间段来添加样式决定的. 要通过 transition进行包裹. 2.在VUE中使用 anim ...
- VMWare WorkStation15--Win10下开机启动虚拟机
参考 https://www.cnblogs.com/qmfsun/p/6284236.html http://www.cnblogs.com/eliteboy/p/7838091.html VMWa ...
- python counter、闭包、generator、解数学方程、异常
1.counter 2.闭包 3.generator 4.解数学方程 5.异常 1.python库——counter from collections import Counter breakfast ...
- C语言之结构体概述
C语言之结构体概述1.结构体类型是一种自定义类型(1)C语言中有2种类型:原生类型和自定义类型.2.结构体使用时先定义结构体类型再用类型定义变量(1)结构体定义时需要先定义结构体类型,再用类型来定义变 ...
- 18 12 18 给服务器添加logging 日志功能
Python中有个logging模块可以完成相关信息的记录,在debug时用它往往事半功倍 1. 日志级别 日志一共分成5个等级,从低到高分别是: DEBUG INFO WARNING ERROR C ...
- Q9:Palindrome Number
9. Palindrome Number 官方的链接:9. Palindrome Number Description : Determine whether an integer is a pali ...
- Runtime之方法交换
在没有一个类的实现源码的情况下,想改变其中一个方法的实现,除了继承它重写.和借助类别重名方法暴力抢先之外,还有就是方法交换 方法交换的原理:在OC中调用一个方法其实是向一个对象发送消息,查找消息的唯一 ...