一、安装 @midwayjs/faas-cli 工具。
   
npm i @midwayjs/faas-cli -g
    
    
    二、生成示例代码
   
f create --template-package=@midwayjs-examples/faas-with-react
终端输出如下:
Generating boilerplate...
√ The directory where the service should be created · my_new_serverless
1...
2...
3...
Enjoy it...
Successfully generated boilerplate for template: "@midwayjs-examples/faas-with-react"
Usage:
    - cd my_new_serverless
    - npm install
    - npm run test
    - and read README.md
Document ❤ Star: https://github.com/midwayjs/midway
记得在vscode安装 alibaba midway 研发助手
Midway Serverless 研发助手
    
     语雀/Alibaba MidwayJs Team/Midway Serverless 使用文档/React 一体化项目
    
   
    
    
    三、安装依赖并运行
   
npm install
npm run dev
    
    
    四、部署
   
f deploy
    需要注意的是,第一次部署需要配置 Aliyun Account ID、Access Key Id、Access Key Secret 等
    
    配置项如下:
    
    
    
    如果报错如下:
   
FC service is not enabled for current user. Please enable FC service before using fun.
You can enable FC service on this page https://www.aliyun.com/product/fc 
    
    
    那是你
    
     没有开通阿里云函数计算服务
    
    ,到
    
     此链接-函数计算
    
    开通即可
   
    显示如下即部署成功:
    
    
    
    但实际上你访问提示信息里给的链接时,实际上是触发了文件下载,这是
    
     由于阿里云默认提供的域名为了避免网络黑灰产等情况,直接通过浏览器访问会自动添加下载header,表现出来的行为就是下载了一个文件。
    
    
    
    五、域名设置
   
如果要部署为可以正常访问的站点或接口,那么需要在f.yml里面配置您的域名,配置规范如下
custom:
  customDomain:
    domainName: 'example.com'
由于国内个人域名要求备案,因此选择部署区域为国内(如 cn-hangzhou / cn-zhangjiakou )等,所配置的域名均需要备案。
如果您的域名没有备案,请选择部署到 cn-hongkong 等非大陆区域。
    如上配置成功后,先不着急执行
    
     f deploy
    
    部署,
    
    因为如果你直接部署的话,不出意外你会报错如下:
   
domain name 你配置的域名 has not been resolved to your FC endpoint, the expected endpoint is '%s'
这是因为你的域名没有设置
CNAME
到指定的
Endpoint
当然你也可能报错如下:
domain name 你配置的域名 has not got ICP license, or the ICP license does not belong to Aliyun
这是因为你的域名没有备案,或备案未接入阿里云。
所以
    你还需要在在域名解析里配置域名
    
     CNAME
    
    指向刚刚部署成功给出的域名,如下所示:
    
     
   
    至此,大功告成!
    
    访问自有域名即可成功查看部署项目!
   
更多内容请查看官方文档:
语雀-midwayjs
    最后,7-25 阿里淘系 midway 技术团队在上海召开了 workshop 沙龙,庆祝自己参加了人生第一个沙龙~
    
    并签到获取了 Alibaba T恤 一件~
    
    撒花~
    
     ★,°
    
    :.☆( ̄▽ ̄)/$:
    
     .°★
    
    。
   
    对了,已经部署成功的服务可以在
    
     阿里云函数计算
    
    找到哦~
    
    无论是监控还是部署都及其简单!
    
    
     serverless
    
    就是这样腻害!
   
 
