-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e3ce762
Showing
22 changed files
with
377 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# 🎨 editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "./node_modules/mwts/", | ||
"ignorePatterns": ["node_modules", "dist", "test", "jest.config.js", "typings"], | ||
"env": { | ||
"jest": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
logs/ | ||
npm-debug.log | ||
yarn-error.log | ||
node_modules/ | ||
package-lock.json | ||
yarn.lock | ||
coverage/ | ||
dist/ | ||
.idea/ | ||
run/ | ||
.DS_Store | ||
*.sw* | ||
*.un~ | ||
.tsbuildinfo | ||
.tsbuildinfo.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
...require('mwts/.prettierrc.json') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
// 使用 IntelliSense 了解相关属性。 | ||
// 悬停以查看现有属性的描述。 | ||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Midway Debug", | ||
"type": "node", | ||
"autoAttachChildProcesses": true, | ||
"console": "integratedTerminal", | ||
"env": { | ||
"NODE_ENV": "local" | ||
}, | ||
"port": 9229, | ||
// "preLaunchTask": "TypeScript compile", | ||
"protocol": "auto", | ||
"request": "launch", | ||
"restart": true, | ||
"runtimeArgs": [ | ||
"run", | ||
"debug", | ||
"--", | ||
"--inspect-brk" | ||
], | ||
"runtimeExecutable": "npm", | ||
"skipFiles": [ | ||
// "${workspaceFolder}/node_modules/**/*.js", | ||
"${workspaceFolder}/node_modules/rxjs/**/*.js", | ||
"<node_internals>/**/*.js" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# my_midway_project | ||
|
||
{{description}} | ||
|
||
## QuickStart | ||
|
||
<!-- add docs here for user --> | ||
|
||
see [midway docs][midway] for more detail. | ||
|
||
### Development | ||
|
||
```bash | ||
$ npm i | ||
$ npm run dev | ||
$ open http://localhost:7001/ | ||
``` | ||
|
||
### Deploy | ||
|
||
```bash | ||
$ npm start | ||
$ npm stop | ||
``` | ||
|
||
### npm scripts | ||
|
||
- Use `npm run lint` to check code style. | ||
- Use `npm test` to run unit test. | ||
|
||
|
||
[midway]: https://midwayjs.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# my_midway_project | ||
|
||
{{description}} | ||
|
||
## 快速入门 | ||
|
||
<!-- 在此次添加使用文档 --> | ||
|
||
如需进一步了解,参见 [midway 文档][midway]。 | ||
|
||
### 本地开发 | ||
|
||
```bash | ||
$ npm i | ||
$ npm run dev | ||
$ open http://localhost:7001/ | ||
``` | ||
|
||
### 部署 | ||
|
||
```bash | ||
$ npm start | ||
$ npm stop | ||
``` | ||
|
||
### 单元测试 | ||
|
||
- [midway-bin] 内置了 [mocha], [thunk-mocha], [power-assert], [istanbul] 等框架,让你可以专注于写单元测试,无需理会配套工具。 | ||
- 断言库非常推荐使用 [power-assert]。 | ||
- 具体参见 [midway 文档 - 单元测试](https://eggjs.org/zh-cn/core/unittest)。 | ||
|
||
### 内置指令 | ||
|
||
- 使用 `npm run lint` 来做代码风格检查。 | ||
- 使用 `npm test` 来执行单元测试。 | ||
- 使用 `npm run autod` 来自动检测依赖更新,详细参见 [autod](https://www.npmjs.com/package/autod) 。 | ||
|
||
|
||
[midway]: https://midwayjs.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "my_midway_project", | ||
"version": "1.0.0", | ||
"description": "{{description}}", | ||
"private": true, | ||
"dependencies": { | ||
"@midwayjs/web": "^2.3.0", | ||
"@midwayjs/decorator": "^2.3.0", | ||
"egg": "^2.0.0", | ||
"egg-scripts": "^2.10.0", | ||
"midway": "^2.3.0" | ||
}, | ||
"devDependencies": { | ||
"@midwayjs/cli": "^1.0.0", | ||
"@midwayjs/egg-ts-helper": "^1.0.1", | ||
"@midwayjs/mock": "^2.3.0", | ||
"@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 && cross-env 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" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "" | ||
}, | ||
"author": "anonymous", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Inject, Controller, Post, Provide, Query } from '@midwayjs/decorator'; | ||
import { Context } from 'egg'; | ||
import { UserService } from '../service/user'; | ||
|
||
@Provide() | ||
@Controller('/api') | ||
export class APIController { | ||
@Inject() | ||
ctx: Context; | ||
|
||
@Inject() | ||
userService: UserService; | ||
|
||
@Post('/get_user') | ||
async getUser(@Query() uid) { | ||
const user = await this.userService.getUser({ uid }); | ||
return { success: true, message: 'OK', data: user }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Controller, Get, Provide } from '@midwayjs/decorator'; | ||
|
||
@Provide() | ||
@Controller('/') | ||
export class HomeController { | ||
@Get('/') | ||
async home() { | ||
return 'Hello Midwayjs!'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Provide } from '@midwayjs/decorator'; | ||
import { IUserOptions } from '../../interface'; | ||
|
||
@Provide() | ||
export class UserService { | ||
async getUser(options: IUserOptions) { | ||
return { | ||
uid: options.uid, | ||
username: 'mockedName', | ||
phone: '12345678901', | ||
email: '[email protected]', | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg'; | ||
|
||
export type DefaultConfig = PowerPartial<EggAppConfig>; | ||
|
||
export default (appInfo: EggAppInfo) => { | ||
const config = {} as DefaultConfig; | ||
|
||
// use for cookie sign key, should change to your own and keep security | ||
config.keys = appInfo.name + '_1602294995416_4568'; | ||
|
||
// add your config here | ||
config.middleware = []; | ||
|
||
return config; | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const security = { | ||
csrf: false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { EggPlugin } from 'egg'; | ||
export default { | ||
static: false, // default is true | ||
} as EggPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @description User-Service parameters | ||
*/ | ||
export interface IUserOptions { | ||
uid: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createApp, close, createHttpRequest } from '@midwayjs/mock'; | ||
import { Framework } from '@midwayjs/web'; | ||
import * as assert from 'assert'; | ||
|
||
describe('test/controller/home.test.ts', () => { | ||
|
||
it('should POST /api/get_user', async () => { | ||
// create app | ||
const app = await createApp<Framework>(); | ||
|
||
// make request | ||
const result = await createHttpRequest(app).post('/api/get_user').query({ uid: 123 }); | ||
|
||
// use expect by jest | ||
expect(result.status).toBe(200); | ||
expect(result.body.message).toBe('OK'); | ||
|
||
// or use assert | ||
assert.deepStrictEqual(result.status, 200); | ||
assert.deepStrictEqual(result.body.data.uid, '123'); | ||
|
||
// close app | ||
await close(app); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { createApp, close, createHttpRequest } from '@midwayjs/mock'; | ||
import { Framework } from '@midwayjs/web'; | ||
import * as assert from 'assert'; | ||
|
||
describe('test/controller/home.test.ts', () => { | ||
|
||
it('should GET /', async () => { | ||
// create app | ||
const app = await createApp<Framework>(); | ||
|
||
// make request | ||
const result = await createHttpRequest(app).get('/'); | ||
|
||
// use expect by jest | ||
expect(result.status).toBe(200); | ||
expect(result.text).toBe('Hello Midwayjs!'); | ||
|
||
// or use assert | ||
assert.deepStrictEqual(result.status, 200); | ||
assert.deepStrictEqual(result.text, 'Hello Midwayjs!'); | ||
|
||
// close app | ||
await close(app); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"compileOnSave": true, | ||
"compilerOptions": { | ||
"target": "ES2018", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"inlineSourceMap":true, | ||
"noImplicitThis": true, | ||
"noUnusedLocals": true, | ||
"stripInternal": true, | ||
"pretty": true, | ||
"declaration": true, | ||
"typeRoots": [ "./typings", "./node_modules/@types"], | ||
"outDir": "dist" | ||
}, | ||
"exclude": [ | ||
"dist", | ||
"node_modules", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// This file is created by [email protected] | ||
// Do not modify this file!!!!!!!!! | ||
|
||
import 'egg'; | ||
import '@midwayjs/web'; | ||
export * from 'egg'; | ||
export as namespace Egg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@midwayjs/web'; |
Oops, something went wrong.