基于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服务器,如果没有可以去阿里云 ...
随机推荐
- PhotoView 实现与图片进行简单的交互
本文的category是根据VIPhotoView来做参考,在此基础上添加个加载网络图片. 此category主要功能是与图片进行交互,双击放大图片,捏合等操作. 感谢vitoziv ! VIPhot ...
- Docker部署Python应用程序
Docker部署Python应用程序 1. 单个py文件部署 生成Dockerfile 文件 插件用的豆瓣的镜像,,重置时间(容器的默认时间是UTC时间与宿主机的相差8小时). 文中需要三个插件(pe ...
- spring boot集成mybatis(1)
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- PGSQL基本操作语句
; --更新数据 ,,) ; --插入数据 ORDER BY app_name,flag asc/desc ; --查询数据并且排序 offset ; --查询起点0开始查询,返回5条数据 ORDER ...
- 使用Kali中的Metasploit生成木马控制Windows系统 (第九天 9.20)
本文转自:https://www.cnblogs.com/yankaohaitaiwei/p/11556921.html 一.kali及Metasploit kali基于debin的数字取证系统,上面 ...
- 51nod 1430:奇偶游戏 博弈
1430 奇偶游戏 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 收藏 关注 有n个城市,第i个城市有ai个人.Daene ...
- AP架构基本过程
①.有线网络搭建(vlan,dhcp,路由等.) ②.ap零配置启动,通过dhcp获取IP地址及网关ip,同时获取ac ip地址. ③.AP主动建立到达ac的capwap隧道. ④.ap与ac建议隧道 ...
- HttpServlet中文乱码问题
客户端提交数据给服务器端(Requset) 如果数据中带有中文的话,有可能会出现乱码情况,那么可以参照以下方法解决. 如果是GET方式 1.代码转码 String username = request ...
- Android进阶——Android事件分发机制之dispatchTouchEvent、onInterceptTouchEvent、onTouchEvent
Android事件分发机制可以说是我们Android工程师面试题中的必考题,弄懂它的原理是我们避不开的任务,所以长痛不如短痛,花点时间干掉他,废话不多说,开车啦 Android事件分发机制的发生在Vi ...
- Android自定义View——多边形网格属性图
1.初始化变量 2.属性图解 3.如果想切换到5.6.7边形等等,则必须修改下面几条数据 4.获取宽和高 5.绘制图形 1.开始画画前:我们要把画笔准备好,这里看代码就能明白意思了,接着把整个 ...