项目初始化

1.安装环境,依赖

1
2
3
4
5
6
npm install ts-node -g
npm init -y
npm i @types/node -D
npm i express -S
npm i @types/express -D
npm i axios -S

2.在项目根目录下新建index.ts

编写测试 接口代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import express, { Express, Router, Request, Response } from "express";
import axios from "axios";

const app: Express = express()

const router: Router = express.Router()

app.use('/api', router)

router.get('list', async (req: Request, res: Response) => {
const result = await axios.get('http://81.71.126.46:9091/user/select/all?currentPage=1')
res.json({
data: result.data
})
})

app.listen(3333, () => {
console.log('sucess server http://localhost:3333')
})

3.在package.json中编写指令

1
2
3
"scripts": {
"dev": "ts-node index.ts"
},

4.在控制台执行指令

1
npm run dev

5.在postman中测试接口