Midway 使用手册

社区版网址:http://www.midwayjs.org/
使用版本:v3
类型:faas

创建项目

1
npm init midway
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ npm init midway
? Hello, traveller.
Which template do you like? …

⊙ v3
koa-v3 - A web application boilerplate with midway v3(koa)
egg-v3 - A web application boilerplate with midway v3(egg)
❯ faas-v3 - A serverless application boilerplate with midway v3(faas)
component-v3 - A midway component boilerplate for v3
quick-start - A midway quickstart exmaple for v3

⊙ v2
web - A web application boilerplate with midway and Egg.js
koa - A web application boilerplate with midway and koa

选择 faas-v3 ,创建完成如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
✔ Hello, traveller.
Which template do you like? · faas-v3 - A serverless application boilerplate with midway v3(faas)
✔ What name would you like to use for the new project? · midway-faas-test
Successfully created project midway-faas-test
Get started with the following commands:

$ cd midway-faas-test
$ npm run dev


Thanks for using Midway

Document ❤ Star: https://github.com/midwayjs/midway

tree -L 4 指令查看目录结构如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
├── README.md
├── f.yml
├── jest.config.js
├── package.json
├── src
│ ├── config
│ │ ├── config.default.ts
│ │ └── config.prod.ts
│ ├── configuration.ts
│ └── function
│ └── hello.ts
├── test
│ └── hello.test.ts
└── tsconfig.json

运行项目

1
npm run dev

成功显示如下:

1
2
3
4
5
6
7
➜  midway-faas-test npm run dev

> midway_faas_project@1.0.0 dev
> cross-env NODE_ENV=local midway-bin dev --ts

[ Midway ] Start Server at http://127.0.0.1:7001
[ Midway ] Start on LAN http://30.24.115.81:7001

默认端口号为 7001。
访问http://127.0.0.1:7001 会返回 Hello midwayjs 。
至此,一个 Midway FaaS 服务创建好了。

修改端口号

如果需要修改开发的启动端口,可以在 package.json 的 scripts 段落里修改,如修改为 6001:

1
2
3
"scripts": {
"dev": "cross-env NODE_ENV=local midway-bin dev --ts --port=6001",
}