mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-11-21 14:13:36 +08:00
project init
This commit is contained in:
21
backend/README.md
Normal file
21
backend/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# 接口
|
||||
|
||||
# 安装依赖
|
||||
```
|
||||
npm install
|
||||
```
|
||||
|
||||
# 项目启动
|
||||
```
|
||||
npm run dev
|
||||
```
|
||||
|
||||
# Swagger文档访问地址
|
||||
http://localhost:3000
|
||||
|
||||
# 注意点
|
||||
请先全局安装typescript、ts-node,如安装请忽略
|
||||
```
|
||||
npm install -g typescript
|
||||
npm install -g ts-node
|
||||
```
|
||||
3376
backend/package-lock.json
generated
Normal file
3376
backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
24
backend/package.json
Normal file
24
backend/package.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "check-ts",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"dev": "ts-node ./src/server.ts",
|
||||
"start": "nodemon ./dist/server.js",
|
||||
"prod": "npm run build && npm run start"
|
||||
},
|
||||
"author": "Coral Ram",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"nodemon": "^1.19.4",
|
||||
"tslint": "^5.20.1",
|
||||
"typescript": "^3.9.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/express": "^4.17.9",
|
||||
"express": "^4.17.1",
|
||||
"express-swagger-generator": "^1.1.17"
|
||||
}
|
||||
}
|
||||
BIN
backend/public/favicon-16x16.png
Normal file
BIN
backend/public/favicon-16x16.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 665 B |
BIN
backend/public/favicon-32x32.png
Normal file
BIN
backend/public/favicon-32x32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 628 B |
59
backend/public/index.html
Normal file
59
backend/public/index.html
Normal file
@@ -0,0 +1,59 @@
|
||||
<!-- HTML for static distribution bundle build -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Swagger UI</title>
|
||||
<link rel="stylesheet" type="text/css" href="./swagger-ui.css">
|
||||
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
|
||||
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
|
||||
<style>
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
*,
|
||||
*:before,
|
||||
*:after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: #fafafa;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
|
||||
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
|
||||
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
|
||||
<script>
|
||||
window.onload = function () {
|
||||
// Begin Swagger UI call region
|
||||
const ui = SwaggerUIBundle({
|
||||
url: "http://localhost:3000/swagger.json",
|
||||
dom_id: '#swagger-ui',
|
||||
deepLinking: true,
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
})
|
||||
// End Swagger UI call region
|
||||
|
||||
window.ui = ui
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
74
backend/public/oauth2-redirect.html
Normal file
74
backend/public/oauth2-redirect.html
Normal file
@@ -0,0 +1,74 @@
|
||||
<!doctype html>
|
||||
<html lang="en-US">
|
||||
<head>
|
||||
<title>Swagger UI: OAuth2 Redirect</title>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
<script>
|
||||
'use strict';
|
||||
function run () {
|
||||
var oauth2 = window.opener.swaggerUIRedirectOauth2;
|
||||
var sentState = oauth2.state;
|
||||
var redirectUrl = oauth2.redirectUrl;
|
||||
var isValid, qp, arr;
|
||||
|
||||
if (/code|token|error/.test(window.location.hash)) {
|
||||
qp = window.location.hash.substring(1);
|
||||
} else {
|
||||
qp = location.search.substring(1);
|
||||
}
|
||||
|
||||
arr = qp.split("&")
|
||||
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
|
||||
qp = qp ? JSON.parse('{' + arr.join() + '}',
|
||||
function (key, value) {
|
||||
return key === "" ? value : decodeURIComponent(value)
|
||||
}
|
||||
) : {}
|
||||
|
||||
isValid = qp.state === sentState
|
||||
|
||||
if ((
|
||||
oauth2.auth.schema.get("flow") === "accessCode"||
|
||||
oauth2.auth.schema.get("flow") === "authorizationCode"
|
||||
) && !oauth2.auth.code) {
|
||||
if (!isValid) {
|
||||
oauth2.errCb({
|
||||
authId: oauth2.auth.name,
|
||||
source: "auth",
|
||||
level: "warning",
|
||||
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
|
||||
});
|
||||
}
|
||||
|
||||
if (qp.code) {
|
||||
delete oauth2.state;
|
||||
oauth2.auth.code = qp.code;
|
||||
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
|
||||
} else {
|
||||
let oauthErrorMsg
|
||||
if (qp.error) {
|
||||
oauthErrorMsg = "["+qp.error+"]: " +
|
||||
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
|
||||
(qp.error_uri ? "More info: "+qp.error_uri : "");
|
||||
}
|
||||
|
||||
oauth2.errCb({
|
||||
authId: oauth2.auth.name,
|
||||
source: "auth",
|
||||
level: "error",
|
||||
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
|
||||
});
|
||||
}
|
||||
} else {
|
||||
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
|
||||
}
|
||||
window.close();
|
||||
}
|
||||
|
||||
window.addEventListener('DOMContentLoaded', function () {
|
||||
run();
|
||||
});
|
||||
</script>
|
||||
3
backend/public/swagger-ui-bundle.js
Normal file
3
backend/public/swagger-ui-bundle.js
Normal file
File diff suppressed because one or more lines are too long
1
backend/public/swagger-ui-bundle.js.map
Normal file
1
backend/public/swagger-ui-bundle.js.map
Normal file
File diff suppressed because one or more lines are too long
3
backend/public/swagger-ui-es-bundle-core.js
Normal file
3
backend/public/swagger-ui-es-bundle-core.js
Normal file
File diff suppressed because one or more lines are too long
1
backend/public/swagger-ui-es-bundle-core.js.map
Normal file
1
backend/public/swagger-ui-es-bundle-core.js.map
Normal file
File diff suppressed because one or more lines are too long
3
backend/public/swagger-ui-es-bundle.js
Normal file
3
backend/public/swagger-ui-es-bundle.js
Normal file
File diff suppressed because one or more lines are too long
1
backend/public/swagger-ui-es-bundle.js.map
Normal file
1
backend/public/swagger-ui-es-bundle.js.map
Normal file
File diff suppressed because one or more lines are too long
3
backend/public/swagger-ui-standalone-preset.js
Normal file
3
backend/public/swagger-ui-standalone-preset.js
Normal file
File diff suppressed because one or more lines are too long
1
backend/public/swagger-ui-standalone-preset.js.map
Normal file
1
backend/public/swagger-ui-standalone-preset.js.map
Normal file
File diff suppressed because one or more lines are too long
4
backend/public/swagger-ui.css
Normal file
4
backend/public/swagger-ui.css
Normal file
File diff suppressed because one or more lines are too long
1
backend/public/swagger-ui.css.map
Normal file
1
backend/public/swagger-ui.css.map
Normal file
File diff suppressed because one or more lines are too long
3
backend/public/swagger-ui.js
Normal file
3
backend/public/swagger-ui.js
Normal file
File diff suppressed because one or more lines are too long
1
backend/public/swagger-ui.js.map
Normal file
1
backend/public/swagger-ui.js.map
Normal file
File diff suppressed because one or more lines are too long
31
backend/src/app.ts
Normal file
31
backend/src/app.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import * as express from "express";
|
||||
import * as bodyParser from "body-parser";
|
||||
|
||||
class App {
|
||||
public app: express.Application;
|
||||
constructor() {
|
||||
this.app = express();
|
||||
this.config();
|
||||
};
|
||||
private config(): void{
|
||||
//支持json编码的主体
|
||||
this.app.use(bodyParser.json());
|
||||
//支持编码的主体
|
||||
this.app.use(bodyParser.urlencoded({
|
||||
extended: true
|
||||
}));
|
||||
//设置静态访问目录(Swagger)
|
||||
this.app.use(express.static('public'));
|
||||
//设置跨域访问
|
||||
this.app.all('*', (req, res, next) => {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
res.header("Access-Control-Allow-Headers", "content-type");
|
||||
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
|
||||
res.header("X-Powered-By", ' 3.2.1');
|
||||
res.header("Content-Type", "application/json;charset=utf-8");
|
||||
next();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new App().app;
|
||||
13
backend/src/router/api/test.ts
Normal file
13
backend/src/router/api/test.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 测试
|
||||
* @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: "成功"})
|
||||
}
|
||||
43
backend/src/server.ts
Normal file
43
backend/src/server.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import app from "./app";
|
||||
const PORT = 3000;
|
||||
const expressSwagger = require('express-swagger-generator')(app)
|
||||
|
||||
// 引入测试数据
|
||||
const test = require("./router/api/test")
|
||||
|
||||
let options = {
|
||||
swaggerDefinition: {
|
||||
info: {
|
||||
description: 'This is a sample server',
|
||||
title: 'Swagger',
|
||||
version: '1.0.0'
|
||||
},
|
||||
host: 'localhost:3000',
|
||||
basePath: '/',
|
||||
produces: ['application/json', 'application/xml'],
|
||||
schemes: ['http', 'https'],
|
||||
securityDefinitions: {
|
||||
JWT: {
|
||||
type: 'apiKey',
|
||||
in: 'header',
|
||||
name: 'Authorization',
|
||||
description: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
route: {
|
||||
url: '/swagger-ui.html',
|
||||
docs: '/swagger.json' //swagger文件 api
|
||||
},
|
||||
basedir: __dirname, //app absolute path
|
||||
files: ['./router/api/*.ts'] //Path to the API handle folder
|
||||
}
|
||||
expressSwagger(options)
|
||||
|
||||
app.get('/getApi', (req, res) => {
|
||||
test.testGetApi(req, res)
|
||||
})
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log('Swagger文档地址:', `http://localhost:${PORT}`);
|
||||
})
|
||||
18
backend/tsconfig.json
Normal file
18
backend/tsconfig.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"pretty": true,
|
||||
"sourceMap": true,
|
||||
"target": "es6",
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./lib"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts", "src/router/api/user.js"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
13
backend/tslint.json
Normal file
13
backend/tslint.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": [
|
||||
"tslint:recommended"
|
||||
],
|
||||
"jsRules": {},
|
||||
"rules": {
|
||||
"interface-name": [false],
|
||||
"no-console": [false],
|
||||
"quotemark": [true, "single"]
|
||||
},
|
||||
"rulesDirectory": []
|
||||
}
|
||||
Reference in New Issue
Block a user