mowatermelon / learn-es6

一个有趣的人写的有趣的前端基础
http://blog.iiwhy.cn/learn-es6
7 stars 5 forks source link

serverless Tencent Test #77

Open mowatermelon opened 4 years ago

mowatermelon commented 4 years ago

Serverless Vue Tencent Cloud

 

在腾讯云部署 Serverless 全栈 WEB 应用 (Vue.js)

用于通过多个 Serverless Components 部署 Serverless 全栈应用程序。可以帮助开发者更方便快捷的部署 Serverless 应用,比如利用后端 API 与前端 Vue.js 结合等场景。

此项目的完全基于腾讯云 Serverless 服务器,可大大缩减使用成本。 如果正在寻找一个低开销的便捷轻量的 Serverless 服务管理框架,这里将是最好的选择。

该示例包括:

该全栈 Web 应用架构图如下: 架构图

mowatermelon commented 4 years ago

部署文档

1. 安装全局依赖

首先,通过如下命令安装 Serverless Framework:

$ npm i -g serverless
npm WARN deprecated superagent@3.8.3: Please note that v5.0.1+ of superagent removes User-Agent header by default, therefore you may need to add it yourself (e.g. GitHub blocks requests without a User-Agent header).  This notice will go away with v5.0.2+ once it is released.
D:\frontEnd\nodejs\serverless -> D:\frontEnd\nodejs\node_modules\serverless\bin\serverless.js
D:\frontEnd\nodejs\sls -> D:\frontEnd\nodejs\node_modules\serverless\bin\serverless.js
D:\frontEnd\nodejs\slss -> D:\frontEnd\nodejs\node_modules\serverless\bin\serverless.js

> serverless@1.60.1 postinstall D:\frontEnd\nodejs\node_modules\serverless
> node ./scripts/postinstall.js

   ┌───────────────────────────────────────────────────┐
   │                                                   │
   │   Serverless Framework successfully installed!    │
   │                                                   │
   │   To start your first project run “serverless”.   │
   │                                                   │
   └───────────────────────────────────────────────────┘

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules\serverless\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ serverless@1.60.1
added 496 packages from 334 contributors in 157.322s

2. 初始化项目

新建一个空的文件夹,使用 create --template-url,安装相关template

$ serverless create --template-url https://github.com/serverless/components/tree/master/templates/tencent-fullstack-vue-application

使用cd命令,进入templates\tencent-fullstack-vue-application 文件夹,可以查看到如下目录结构:

$ tencent-fullstack-vue-application>tree
卷 文件盘 的文件夹 PATH 列表
卷序列号为 7821-3508
E:.
├─api
└─dashboard
    └─src
        ├─fonts
        └─images
|- .env_temp      # 
|- package.json      # 主项目项目依赖管理
|- README.md      # 示例项目的中文使用说明
|- README_EN.md     # 示例项目的英文使用说明
|- serverless.yml      # 使用项目中的 yml 文件

4. 分别安装独立依赖

dashboard文件夹,安装独立依赖

$ >templates\tencent-fullstack-vue-application cd dashboard
$ >templates\tencent-fullstack-vue-application\dashboard npm i
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.

> deasync@0.1.19 install E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\dashboard\node_modules\deasync
> node ./build.js

`win32-x64-node-12` exists; testing
Binary is fine; exiting

> core-js@2.6.11 postinstall E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\dashboard\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

> parcel@1.12.4 postinstall E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\dashboard\node_modules\parcel
> node -e "console.log('\u001b[35m\u001b[1mLove Parcel? You can now donate to our open collective:\u001b[22m\u001b[39m\n > \u001b[34mhttps://opencollective.com/parcel/donate\u001b[0m')"

Love Parcel? You can now donate to our open collective:
 > https://opencollective.com/parcel/donate
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN tencent-fullstack-vue-app@0.0.0 No description
npm WARN tencent-fullstack-vue-app@0.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 752 packages from 536 contributors and audited 9061 packages in 106.115s
found 0 vulnerabilities

api 文件夹,安装独立依赖

$ >templates\tencent-fullstack-vue-application cd api
$ >templates\tencent-fullstack-vue-application\api npm i
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN tencent-fullstack-vue-api@0.0.0 No description
npm WARN tencent-fullstack-vue-api@0.0.0 No repository field.

added 52 packages from 39 contributors and audited 129 packages in 7.643s
found 0 vulnerabilities

5. 正式部署项目

回到tencent-fullstack-vue-application目录下,直接通过 serverless 命令来部署应用:

$ >templates\tencent-fullstack-vue-application serverless

如果希望查看部署详情,可以通过调试模式的命令 serverless --debug 进行部署。

如您的账号未登陆注册腾讯云,您可以直接通过微信扫描命令行中的二维码进行授权登陆和注册。

部署成功后,可以直接在浏览器中访问日志中返回的 dashboard url 地址,查看该全栈 Web app 的效果:

serverless --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.

Please scan QR code login from wechat
Wait login...
Login successful for TencentCloud
  DEBUG ─ Compressing function tencent-fullstack-vue-api file to E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\.serverless/tencent-fullstack-vue-api.zip.
  DEBUG ─ Compressed function tencent-fullstack-vue-api file successful
  DEBUG ─ Uploading service package to cos[sls-cloudfunction-ap-guangzhou-code]. sls-cloudfunction-default-tencent-fullstack-vue-api-1576906473.zip
  DEBUG ─ Uploaded package successful E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\.serverless/tencent-fullstack-vue-api.zip
  DEBUG ─ Creating function tencent-fullstack-vue-api
  DEBUG ─ Created function tencent-fullstack-vue-api successful
  DEBUG ─ Setting tags for function tencent-fullstack-vue-api
  DEBUG ─ Creating trigger for function tencent-fullstack-vue-api
  DEBUG ─ Deployed function tencent-fullstack-vue-api successful
  DEBUG ─ Starting API-Gateway deployment with name api.TencentApiGateway in the ap-guangzhou region
  DEBUG ─ Service with ID service-6kwbv8ss created.
  DEBUG ─ API with id api-h9crvdpk created.
  DEBUG ─ Deploying service with id service-6kwbv8ss.
  DEBUG ─ Deployment successful for the api named api.TencentApiGateway in the ap-guangzhou region.
  DEBUG ─ Starting Website Component.
  DEBUG ─ Preparing website Tencent COS bucket oxxvw3h-cvqr2sk-1253613838.
  DEBUG ─ Deploying "oxxvw3h-cvqr2sk-1253613838" bucket in the "ap-guangzhou" region.
  DEBUG ─ "oxxvw3h-cvqr2sk-1253613838" bucket was successfully deployed to the "ap-guangzhou" region.
  DEBUG ─ Setting ACL for "oxxvw3h-cvqr2sk-1253613838" bucket in the "ap-guangzhou" region.
  DEBUG ─ Ensuring no CORS are set for "oxxvw3h-cvqr2sk-1253613838" bucket in the "ap-guangzhou" region.
  DEBUG ─ Ensuring no Tags are set for "oxxvw3h-cvqr2sk-1253613838" bucket in the "ap-guangzhou" region.
  DEBUG ─ Configuring bucket oxxvw3h-cvqr2sk-1253613838 for website hosting.
  DEBUG ─ Bundling website environment variables.
  DEBUG ─ Website env written to file E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\dashboard\env.js.
  DEBUG ─ Running npm run build in E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\dashboard.
  DEBUG ─ Uploading website files from E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\dashboard\dist to bucket oxxvw3h-cvqr2sk-1253613838.
  DEBUG ─ Starting upload to bucket oxxvw3h-cvqr2sk-1253613838 in region ap-guangzhou
  DEBUG ─ Uploading directory E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\dashboard\dist to bucket oxxvw3h-cvqr2sk-1253613838
  DEBUG ─ Website deployed successfully to URL: http://oxxvw3h-cvqr2sk-1253613838.cos-website.ap-guangzhou.myqcloud.com.

  dashboard:
    url: http://oxxvw3h-cvqr2sk-1253613838.cos-website.ap-guangzhou.myqcloud.com
    env:
      apiUrl: https://service-6kwbv8ss-1253613838.gz.apigw.tencentcs.com/release/
  api:
    region:              ap-guangzhou
    functionName:        tencent-fullstack-vue-api
    apiGatewayServiceId: service-6kwbv8ss
    url:                 https://service-6kwbv8ss-1253613838.gz.apigw.tencentcs.com/release/

  38s » dashboard » done

mowatermelon commented 4 years ago

预览案例效果

预览dashboard效果

默认查看效果

默认查看效果

点击交互效果

点击交互效果


预览api效果

image


mowatermelon commented 4 years ago

注意事项

  1. 首次部署成功后,也可以通过以下命令,在本地运行服务,并与后端腾讯云服务进行通讯:
$ cd dashboard && npm run start

  1. 目前暂不支持淘宝等第三方 npm 源,如报错Component "@serverless/tencent-express" was not found on NPM nor could it be resolved locally.请设置并使用 npm 官方源体验:
$ npm config rm registry
$ npm set registry https://registry.npmjs.org/

  1. 腾讯云 Component 已支持二维码一键登录,如您希望使用配置秘钥的方式登录,也可以参考如下步骤:

tencent-fullstack-vue-application 文件夹根目录创建 .env 文件

$ touch .env # 腾讯云的配置信息

.env 文件中配置腾讯云的 SecretIdSecretKey 信息并保存

# .env
TENCENT_SECRET_ID=123
TENCENT_SECRET_KEY=123

4.不能使用yarn进行安装依赖,请注意使用 npm进行安装依赖

$ yarn
yarn install v1.16.0
error ..\package.json: Name contains illegal characters
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

5.注意在执行了serverless --debug,之后,如果未登陆腾讯云账号,在启动日志输出DEBUG ─ Executing the template's components graph.之后,这边会出现登陆的二维码,这个二维码请求登陆对应接口,是有时间限制的, 请注意及时扫码登陆,如果未及时扫描登陆,哪怕之后利用收集扫码登陆成功了,这个时候还不能正常启动服务。

目前不清楚这个默认的等待时长是多少,日常托腮.jpg

询问了官方人员之后,反馈这个等待时间跟当前的:网络状况,服务部署执行时间,都有关系。

$ Please scan QR code login from wechat
Wait login...
Login timeout. please login again
  163s » api » Deploying ..
mowatermelon commented 4 years ago

sls其他指令说明

sls -v 查看版本信息

$ sls -v
Framework Core: 1.60.1
Plugin: 3.2.6
SDK: 2.2.1
Components Core: 1.1.2
Components CLI: 1.4.0

sls -help 查看指令帮助说明

$ sls -help

Commands
* You can run commands with "serverless" or the shortcut "sls"
* Pass "--verbose" to this command to get in-depth plugin info
* Pass "--no-color" to disable CLI colors
* Pass "--help" after any <command> for contextual help

Interactive Quickstart
* Run serverless (or shortcut sls) without any arguments to initialize an interactive setup
  of functionalities related to given service or current environment
* Pass "--help-interactive" for contextual help on interactive CLI options

Framework
* Documentation: http://slss.io/docs

Environment Variables
* Set SLS_DEBUG=* to see debugging logs
* Set SLS_WARNING_DISABLE=* to hide warnings from the output

config ........................ Configure Serverless
config credentials ............ Configures a new provider profile for the Serverless Framework
create ........................ Create new Serverless service
install ....................... Install a Serverless service from GitHub or a plugin from the Serverless registry
package ....................... Packages a Serverless service
deploy ........................ Deploy a Serverless service
deploy function ............... Deploy a single function from the service
deploy list ................... List deployed version of your Serverless Service
deploy list functions ......... List all the deployed functions and their versions
invoke ........................ Invoke a deployed function
invoke local .................. Invoke function locally
info .......................... Display information about the service
logs .......................... Output the logs of a deployed function
metrics ....................... Show metrics for a specific function
print ......................... Print your compiled and resolved config file
remove ........................ Remove Serverless service and all resources
rollback ...................... Rollback the Serverless service to a specific deployment
rollback function ............. Rollback the function to the previous version
slstats ....................... Enable or disable stats
plugin ........................ Plugin management for Serverless
plugin install ................ Install and add a plugin to your service
plugin uninstall .............. Uninstall and remove a plugin from your service
plugin list ................... Lists all available plugins
plugin search ................. Search for plugins
login ......................... Login or sign up for Serverless
logout ........................ Logout from Serverless
generate-event ................ Generate event
test .......................... Run HTTP tests
dashboard ..................... Open the Serverless dashboard

Plugins
AwsConfigCredentials, Config, Create, Deploy, Executable, Info, Install, InteractiveCli, Invoke, Logs, Metrics, Package, Plugin, PluginInstall, PluginList, PluginSearch, PluginUninstall, Print, Remove, Rollback, ServerlessEnterprisePlugin, SlStats

sls --debug 启动服务

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 ─ Compressing function tencent-fullstack-vue-api file to E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\.serverless/tencent-fullstack-vue-api.zip.
  DEBUG ─ Compressed function tencent-fullstack-vue-api file successful
  DEBUG ─ Uploading service package to cos[sls-cloudfunction-ap-guangzhou-code]. sls-cloudfunction-default-tencent-fullstack-vue-api-1576917683.zip
  DEBUG ─ Uploaded package successful E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\.serverless/tencent-fullstack-vue-api.zip
  DEBUG ─ Creating function tencent-fullstack-vue-api
  DEBUG ─ Updating code...
  DEBUG ─ Updating configure...
  DEBUG ─ Created function tencent-fullstack-vue-api successful
  DEBUG ─ Setting tags for function tencent-fullstack-vue-api
  DEBUG ─ Creating trigger for function tencent-fullstack-vue-api
  DEBUG ─ Deployed function tencent-fullstack-vue-api successful
  DEBUG ─ Starting API-Gateway deployment with name api.TencentApiGateway in the ap-guangzhou region
  DEBUG ─ Using last time deploy service id service-6kwbv8ss
  DEBUG ─ Updating service with serviceId service-6kwbv8ss.
  DEBUG ─ Endpoint ANY / already exists with id api-h9crvdpk.
  DEBUG ─ Updating api with api id api-h9crvdpk.
  DEBUG ─ Service with id api-h9crvdpk updated.
  DEBUG ─ Deploying service with id service-6kwbv8ss.
  DEBUG ─ Deployment successful for the api named api.TencentApiGateway in the ap-guangzhou region.
  DEBUG ─ Starting Website Component.
  DEBUG ─ Preparing website Tencent COS bucket oxxvw3h-cvqr2sk-1253613838.
  DEBUG ─ Bucket "oxxvw3h-cvqr2sk-1253613838" in the "ap-guangzhou" region already exist.
  DEBUG ─ Setting ACL for "oxxvw3h-cvqr2sk-1253613838" bucket in the "ap-guangzhou" region.
  DEBUG ─ Ensuring no CORS are set for "oxxvw3h-cvqr2sk-1253613838" bucket in the "ap-guangzhou" region.
  DEBUG ─ Ensuring no Tags are set for "oxxvw3h-cvqr2sk-1253613838" bucket in the "ap-guangzhou" region.
  DEBUG ─ Configuring bucket oxxvw3h-cvqr2sk-1253613838 for website hosting.
  DEBUG ─ Bundling website environment variables.
  DEBUG ─ Website env written to file E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\dashboard\env.js.
  DEBUG ─ Running npm run build in E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\dashboard.
  DEBUG ─ Uploading website files from E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\dashboard\dist to bucket oxxvw3h-cvqr2sk-1253613838.
  DEBUG ─ Starting upload to bucket oxxvw3h-cvqr2sk-1253613838 in region ap-guangzhou
  DEBUG ─ Uploading directory E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application\dashboard\dist to bucket oxxvw3h-cvqr2sk-1253613838
  DEBUG ─ Website deployed successfully to URL: http://oxxvw3h-cvqr2sk-1253613838.cos-website.ap-guangzhou.myqcloud.com.

  dashboard:
    url: http://oxxvw3h-cvqr2sk-1253613838.cos-website.ap-guangzhou.myqcloud.com
    env:
      apiUrl: https://service-6kwbv8ss-1253613838.gz.apigw.tencentcs.com/release/
      domain: iiwhy.com
  api:
    region:              ap-guangzhou
    functionName:        tencent-fullstack-vue-api
    apiGatewayServiceId: service-6kwbv8ss
    url:                 https://service-6kwbv8ss-1253613838.gz.apigw.tencentcs.com/release/

  32s » dashboard » done

sls remove --debug 关闭服务

$ sls remove --debug # 如果已经有启动的服务,执行的效果

  DEBUG ─ Flushing template state and removing all components.
  DEBUG ─ Starting Website Removal.
  DEBUG ─ Removing Website bucket.
  DEBUG ─ Removing files from the "oxxvw3h-cvqr2sk-1253613838" bucket.
  DEBUG ─ Removing function
  DEBUG ─ Removing "oxxvw3h-cvqr2sk-1253613838" bucket from the "ap-guangzhou" region.
  DEBUG ─ Request id
  DEBUG ─ Removed function tencent-fullstack-vue-api successful
  DEBUG ─ "oxxvw3h-cvqr2sk-1253613838" bucket was successfully removed from the "ap-guangzhou" region.
  DEBUG ─ Finished Website Removal.
  DEBUG ─ Removing any previously deployed API. api-h9crvdpk
  DEBUG ─ Removing any previously deployed service. service-6kwbv8ss

  6s » dashboard » done

$ sls remove --debug # 如果所有服务已经关闭,这边关闭服务会直接提示没有关闭的服务

  DEBUG ─ Flushing template state and removing all components.

  0s » Template » done
mowatermelon commented 4 years ago

.env文件配置说明

参数说明

参数说明仅个人理解

属性名 属性名说明
SecretId 个人账号标识
SecretKey 个人私钥
AppId 应用标识
token 请求自带鉴权
expired 过期时间
signature 携带指纹
uuid 个人唯一id
timestamp 请求时间戳

完整案例

在扫描登陆腾讯云之后,本地项目根文件夹就会有一个.env_temp文件。

{
  "SecretId": "",
  "SecretKey": "",
  "AppId": "1253613838",
  "token": "83ddce0bb76981a6028bbd3ae9c65386e1d90c4020001",
  "expired": 1576924883,
  "signature": "d2a8ee79e2980d39dd37dbf81de26d64",
  "uuid": "6278ccc7-e3d5-4231-9483-e3c4ed3417d5",
  "timestamp": 1576917683.852
}

分析时间戳

这边将时间戳的值转换成对应的日期格式,得到的反馈值是1970/1/19,是说永不过期的意思吗?

new Date(1576924883).toLocaleDateString("zh-CN", {hour12: false})
"1970/1/19"

分析AppId

原有数据

AppId1253613838

服务类型 实际地址
dashboard http://oxxvw3h-zprhnbb-${AppId}.cos-website.ap-guangzhou.myqcloud.com
api https://service-ryotk4b0-${AppId}.gz.apigw.tencentcs.com/release/

尝试改变这个值 为2253613838

尝试关闭已经启动的服务,提示需要重新登陆。

$ sls remove --debug

  DEBUG ─ Flushing template state and removing all components.
  DEBUG ─ Starting Website Removal.
  DEBUG ─ Removing Website bucket.

Please scan QR code login from wechat
Wait login...

Login timeout. please login again
  71s » dashboard » Removing ...

尝试启动的服务,提示需要重新登陆。

$ 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.

Please scan QR code login from wechat
Wait login...

Login timeout. please login again
  73s » dashboard » Removing ...

将对应的值改回1253613838

尝试将值改回之后,这边成功关闭服务了。

$ sls remove --debug

  DEBUG ─ Flushing template state and removing all components.
  DEBUG ─ Starting Website Removal.
  DEBUG ─ Removing Website bucket.
  DEBUG ─ Removing files from the "oxxvw3h-zprhnbb-1253613838" bucket.
  DEBUG ─ Removing function
  DEBUG ─ Request id
  DEBUG ─ Removed function tencent-fullstack-vue-api successful
  DEBUG ─ Removing "oxxvw3h-zprhnbb-1253613838" bucket from the "ap-guangzhou" region.
  DEBUG ─ "oxxvw3h-zprhnbb-1253613838" bucket was successfully removed from the "ap-guangzhou" region.
  DEBUG ─ Finished Website Removal.
  DEBUG ─ Removing any previously deployed API. api-08pjptka
  DEBUG ─ Removing any previously deployed service. service-ryotk4b0

  7s » dashboard » done
mowatermelon commented 4 years ago

关闭服务之后

预览dashboard效果

页面效果

预览api效果

请求实际返回

<html>
<head><title>404 Not Found</title></head>
<body>
<h1>404 Not Found</h1>
<ul>
<li>Code: NoSuchBucket</li>
<li>Message: The specified bucket does not exist.</li>
<li>Key: </li>
<li>RequestId: NWRmZGU0ZWVfMWRiMjk0MGFfNjRlM180M2U1MGY=</li>
<li>TraceId: OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OTQ5YWUxMjNkYTk3NzdjZmZlMDQzOTgxOThkOTNlOWFkNGJiZjUyZDQ5OTBmNDllMjU4ZWNlN2Q5Y2RkMTMzZDM=</li>
</ul>
</body>
</html>

预览api效果

预览api效果


总结

关于http://xxx.cos-website.ap-guangzhou.myqcloud.com/对应服务有对应路由转发控制,如果服务关闭,这边访问会有对应404html片段。

但是请求https://xxx.gz.apigw.tencentcs.com/release/地址服务是直接关闭,访问直接被拒绝。

mowatermelon commented 4 years ago

package.json 依赖分析

根路径package.json 依赖分析

{
  "name": "templates\\tencent-fullstack-vue-application",
  "version": "0.0.0",
  "dependencies": {
    "@serverless/tencent-express": "^2.0.0",
    "@serverless/tencent-website": "^1.2.0"
  },
  "devDependencies": {
    "@serverless/eslint-config": "^1.2.1",
    "eslint": "^6.6.0",
    "eslint-plugin-import": "^2.18.2",
    "prettier": "^1.18.2"
  },
  "eslintConfig": {
    "extends": "@serverless/eslint-config/node",
    "root": true,
    "parserOptions": {
      "ecmaVersion": 2018
    }
  },
  "license": "ISC"
}

dashboard文件夹中package.json 依赖分析

{
  "name": "tencent-fullstack-vue-app",
  "version": "0.0.0",
  "description": "",
  "dependencies": {
    "vue": "^2.6.10"
  },
  "scripts": {
    "start": "parcel index.html",
    "build": "parcel build index.html"
  },
  "alias": {
    "vue": "./node_modules/vue/dist/vue.common.js"
  },
  "eslintConfig": {
    "env": {
      "browser": true
    }
  },
  "browserslist": [
    "last 1 Chrome version"
  ],
  "license": "ISC",
  "devDependencies": {
    "cssnano": "^4.1.10",
    "parcel": "^1.12.4"
  }
}

api文件夹中package.json 依赖分析

{
  "name": "tencent-fullstack-vue-api",
  "version": "0.0.0",
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.17.1"
  },
  "license": "ISC"
}

mowatermelon commented 4 years ago

.serverless文件夹分析

文件说明

|- Template.api.TencentApiGateway.json
|- Template.api.TencentCloudFunction.json
|- Template.dashboard.json
|- Template.dashboard.websiteBucket.json
|- Template.json
|- _.json
|- tencent-fullstack-vue-api.zip

Template.api.TencentApiGateway.json

{
  "protocols": [
    "https"
  ],
  "subDomain": "service-2rkukzk8-1253613838.gz.apigw.tencentcs.com",
  "environment": "release",
  "region": "ap-guangzhou",
  "service": {
    "value": "service-2rkukzk8",
    "created": true
  },
  "apis": [
    {
      "path": "/",
      "method": "ANY",
      "apiId": {
        "value": "api-27pjnthg",
        "created": true
      }
    }
  ]
}

Template.api.TencentCloudFunction.json

{
  "deployed": {
    "Name": "tencent-fullstack-vue-api",
    "Runtime": "Nodejs8.9",
    "Handler": "index.handler",
    "MemorySize": 128,
    "Timeout": 3,
    "Region": "ap-guangzhou",
    "Role": "QCS_SCFExcuteRole",
    "Description": "This is a template function"
  }
}

Template.dashboard.json

{
  "bucketName": "oxxvw3h-m2qa8es-1253613838",
  "region": "ap-guangzhou",
  "url": "http://oxxvw3h-m2qa8es-1253613838.cos-website.ap-guangzhou.myqcloud.com"
}

Template.dashboard.websiteBucket.json

{
  "bucket": "oxxvw3h-m2qa8es-1253613838",
  "region": "ap-guangzhou"
}

Template.json

{
  "components": {
    "dashboard": "C:\\Users\\86342\\.serverless\\components\\registry\\npm\\@serverless\\tencent-website@1.2.11\\node_modules\\@serverless\\tencent-website",
    "api": "C:\\Users\\86342\\.serverless\\components\\registry\\npm\\@serverless\\tencent-express@2.0.0\\node_modules\\@serverless\\tencent-express"
  }
}

_.json

{
  "id": "oxxvw3h"
}

mowatermelon commented 4 years ago

相关错误说明

二维码未显示问题

当终端窗口所有resize之后,登陆二维码会消失不见,

 二维码未显示问题


指令执行失败问题

指令执行失败问题

$ sls config

  error:
  Error: "component" input is required to run custom methods
    at Proxy.<anonymous> (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\template\utils.js:350:13)
    at Object.runComponents (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\cli\src\index.js:209:40)

E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application>sls config credentials

  error:
  Error: "component" input is required to run custom methods
    at Proxy.<anonymous> (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\template\utils.js:350:13)
    at Object.runComponents (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\cli\src\index.js:209:40)

E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application>sls create

  error:
  Error: "component" input is required to run custom methods
    at Proxy.<anonymous> (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\template\utils.js:350:13)
    at Object.runComponents (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\cli\src\index.js:209:40)

E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application>sls install

  error:
  Error: "component" input is required to run custom methods
    at Proxy.<anonymous> (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\template\utils.js:350:13)
    at Object.runComponents (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\cli\src\index.js:209:40)

E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application>sls deploy

  error:
  Error: "component" input is required to run custom methods
    at Proxy.<anonymous> (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\template\utils.js:350:13)
    at Object.runComponents (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\cli\src\index.js:209:40)

E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application>sls info

  error:
  Error: "component" input is required to run custom methods
    at Proxy.<anonymous> (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\template\utils.js:350:13)
    at Object.runComponents (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\cli\src\index.js:209:40)

E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application>sls logs

  error:
  Error: "component" input is required to run custom methods
    at Proxy.<anonymous> (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\template\utils.js:350:13)
    at Object.runComponents (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\cli\src\index.js:209:40)

E:\bak\OneDrive\documentBak\learn\serverless\templates\tencent-fullstack-vue-application>sls plugin list

  error:
  Error: "component" input is required to run custom methods
    at Proxy.<anonymous> (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\template\utils.js:350:13)
    at Object.runComponents (D:\frontEnd\nvm\v12.4.0\node_modules\serverless\node_modules\@serverless\cli\src\index.js:209:40)
lianyi commented 4 years ago

got the same problem

  Error: "component" input is required to run custom methods
node -v && npm -v
v8.11.3
6.13.6
sls -v
Framework Core: 1.61.3
Plugin: 3.2.7
SDK: 2.3.0
Components Core: 1.1.2
Components CLI: 1.4.0