接口规范

This commit is contained in:
xiaoxian521 2020-11-29 23:28:35 +08:00
parent 9a5af7427c
commit ef15fa71ba
6 changed files with 129 additions and 22 deletions

View File

@ -1,5 +1,5 @@
import * as bodyParser from 'body-parser'; import * as express from "express";
import * as express from 'express'; import * as bodyParser from "body-parser";
class App { class App {
public app: express.Application; public app: express.Application;

View File

@ -1,6 +1,6 @@
import * as dotenv from 'dotenv'; import * as dotenv from "dotenv";
process.env.NODE_ENV = process.env.NODE_ENV || 'development'; process.env.NODE_ENV = process.env.NODE_ENV || "development";
const envFound = dotenv.config(); const envFound = dotenv.config();
if (envFound.error) { if (envFound.error) {

View File

@ -1,6 +1,6 @@
import config from '../config'; import config from "../config";
import * as winston from 'winston'; import * as winston from "winston";
const transports = []; const transports = [];
if(process.env.NODE_ENV !== 'development') { if(process.env.NODE_ENV !== 'development') {

View File

@ -0,0 +1,93 @@
import { Request, Response } from "express"
/**
*
* @route GET /login/
* @summary
* @group login -
* @returns {object} 200
* @security JWT
* @returns {Error} default - Unexpected error
*/
const login =async (req: Request, res: Response) => {
res.json({code:1 , msg: "成功"})
}
/**
*
* @route GET /register/
* @summary
* @group register -
* @returns {object} 200
* @security JWT
* @returns {Error} default - Unexpected error
*/
const register =async (req: Request, res: Response) => {
res.json({code:1 , msg: "成功"})
}
/**
*
* @route GET /updateList/
* @summary
* @group updateList -
* @returns {object} 200
* @security JWT
* @returns {Error} default - Unexpected error
*/
const updateList =async (req: Request, res: Response) => {
res.json({code:1 , msg: "成功"})
}
/**
*
* @route GET /deleteList/
* @summary
* @group deleteList -
* @returns {object} 200
* @security JWT
* @returns {Error} default - Unexpected error
*/
const deleteList =async (req: Request, res: Response) => {
res.json({code:1 , msg: "成功"})
}
/**
*
* @route GET /searchPage/
* @summary
* @group searchPage -
* @returns {object} 200
* @security JWT
* @returns {Error} default - Unexpected error
*/
const searchPage =async (req: Request, res: Response) => {
res.json({code:1 , msg: "成功"})
}
/**
*
* @route GET /searchVague/
* @summary
* @group searchVague -
* @returns {object} 200
* @security JWT
* @returns {Error} default - Unexpected error
*/
const searchVague =async (req: Request, res: Response) => {
res.json({code:1 , msg: "成功"})
}
export {
login,
register,
updateList,
deleteList,
searchPage,
searchVague,
}

View File

@ -1,13 +0,0 @@
/**
*
* @route GET /getApi/
* @summary
* @group test -
* @returns {object} 200
* @security JWT
* @returns {Error} default - Unexpected error
*/
exports.testGetApi = (req, res) => {
res.json({code:1 , msg: "成功"})
}

View File

@ -10,10 +10,37 @@ expressSwagger(config.options)
queryTable(user) queryTable(user)
// 引入测试数据 // 引入测试数据
const test = require("./router/api/test") import {
login,
register,
updateList,
deleteList,
searchPage,
searchVague,
} from "./router/api/mysql"
app.get('/getApi', (req, res) => { app.get('/login', (req, res) => {
test.testGetApi(req, res) login(req, res)
})
app.get('/register', (req, res) => {
register(req, res)
})
app.get('/updateList', (req, res) => {
updateList(req, res)
})
app.get('/deleteList', (req, res) => {
deleteList(req, res)
})
app.get('/register', (req, res) => {
register(req, res)
})
app.get('/searchVague', (req, res) => {
searchVague(req, res)
}) })
app.listen(config.port, () => { app.listen(config.port, () => {