-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (50 loc) · 1.69 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* eslint-disable */
const express = require('express');
const app = express();
const cors = require('cors');
const swaggerUi = require('swagger-ui-express');
const swaggerJSDoc = require('swagger-jsdoc');
const swaggerModelValidator = require('swagger-model-validator');
const options = {
swaggerDefinition: {
openapi: '3.0.0',
info: {
title: 'Hero server API',
version: '1.0.0',
},
servers: [ {
url: 'https://heroes-hahow.herokuapp.com',
description: 'development'
}, {
url: 'http://127.0.0.1:3100',
description: 'local'
} ],
schemes: [ 'http' ],
basePath: '/'
},
apis: [
// tags --------------------------------------------------------------------------------------------
'./api/tags.yaml',
// schema --------------------------------------------------------------------------------------------
'./api/schemas/*.yaml',
// parameters --------------------------------------------------------------------------------------------
'./api/parameters/*.yaml',
// router --------------------------------------------------------------------------------------------
// Hero
'./api/paths/ListHeroes.yaml', // 取得英雄列表
'./api/paths/SingleHero.yaml', // 取得單一英雄
]
};
const swaggerSpec = swaggerJSDoc(options);
swaggerModelValidator(swaggerSpec);
// OpenAPI JSON 格式
// https://swagger.io/specification/
app.get('/swagger.json', cors(), function (req, res) {
res.setHeader('Content-Type', 'application/json');
res.send(swaggerSpec);
});
// Render swagger 網站
app.use('/', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.listen(3000, () => {
console.log('listening on port: 3000');
});