欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

阿里云云开发Web应用训练营day06

程序员文章站 2022-06-13 12:32:52
...

1.打卡阿里云云开发平台 https://workbench.aliyun.com/
2.创建新应用
阿里云云开发Web应用训练营day06
阿里云云开发Web应用训练营day06
3.开发部署
4.将除.workbench以外的所有文件删除
5.安装cli,终端输入

npm i -g @midwayjs/cli
npm i -g @midwayjs/faas-cli -g

6.验证cli是否安装成功,终端输入

mw -v
f -v

成功显示

Node.js v10.15.1
@midwayjs/cli v1.2.19

Node.js v10.15.1
@midwayjs/faas-cli v1.2.14

7.创建应用到当前文件夹下,终端输入

mw new .

回车 回车

阿里云云开发Web应用训练营day06
8.如果.workbench文件丢失,手动创建.workbench文件粘贴以下代码

{
  "fcRouteDefault": [
    {
      "apiUri": "/*",
      "fcHandler": "index.handler",
      "httpMethod": "ANY"
    }
  ],
  "cicd": {
    "package": "rm -rf package-lock.json && npx f package && mv serverless.zip code.zip && rm -rf .serverless"
  }
}

9.保存文件关掉Cloud IDE再重新打卡,否则
阿里云云开发Web应用训练营day06
10.终端执行

npm run dev

阿里云云开发Web应用训练营day06

11.再打卡一个终端

阿里云云开发Web应用训练营day06

输入

curl http://127.0.0.1:7001

阿里云云开发Web应用训练营day06

12.新建文件f.yml,内容如下

service: my-midawy-app

provider:
  name: aliyun

deployType: egg

保存

13.把package.json文件内容修改为以下内容

{
  "name": "my_midway_project",
  "version": "1.0.0",
  "description": "{{description}}",
  "private": true,
  "dependencies": {
    "@midwayjs/web": "^2.0.0",
    "@midwayjs/decorator": "^2.2.1",
    "egg": "^2.0.0",
    "egg-scripts": "^2.10.0",
    "midway": "^2.0.0"
  },
  "devDependencies": {
    "@midwayjs/cli": "^1.0.0",
    "@midwayjs/egg-ts-helper": "^1.0.1",
    "@midwayjs/mock": "^2.2.6",
    "@types/jest": "^26.0.10",
    "@types/node": "14",
    "cross-env": "^6.0.0",
    "mwts": "^1.0.5",
    "jest": "^26.4.0",
    "ts-jest": "^26.2.0",
    "typescript": "^3.9.0"
  },
  "engines": {
    "node": ">=12.0.0"
  },
  "scripts": {
    "start": "egg-scripts start --daemon --title=midway-server-my_midway_project --framework=midway",
    "stop": "egg-scripts stop --title=midway-server-my_midway_project",
    "start_build": "npm run build && cross-env NODE_ENV=development midway-bin dev",
    "dev": "cross-env ets && NODE_ENV=local midway-bin dev --ts",
    "debug": "cross-env NODE_ENV=local midway-bin debug --ts",
    "test": "midway-bin test",
    "cov": "midway-bin cov",
    "lint": "mwts check",
    "lint:fix": "mwts fix",
    "ci": "npm run cov",
    "build": "midway-bin build -c"
  },
  "midway-bin-clean": [
    ".vscode/.tsbuildinfo",
    "dist"
  ],
  "midway-integration": {
    "lifecycle": {
      "before:package:cleanup": "npm run build"
    }
  },
  "egg":{
    "framework": "@midwayjs/web"
  },
  "repository": {
    "type": "git",
    "url": ""
  },
  "author": "anonymous",
  "license": "MIT"
}

14.部署
阿里云云开发Web应用训练营day06