-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
155 lines (145 loc) · 4.24 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import express from 'express';
import cors from 'cors';
import swagger from './swagger.js';
import {getAll, getById, getFavorites} from './builds.js';
const app = express();
app.use(express.json(), cors());
const corsOptions = {
"origin": "*",
"optionsSuccessStatus": 200
};
app.use(cors(corsOptions));
/**
* @openapi
* /:
* get:
* description: Welcome to aoe4guides!
* responses:
* 200:
* description: Returns just a string.
*/
app.get("/", (req, res) => {
res.send(`Welcome to aoe4guides-api!`);
});
/**
* @openapi
* /status:
* get:
* description: Allows checking the status of the service
* responses:
* 200:
* description: Returns "Running" when the service is available.
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/status'
*/
app.get("/status", (req, res) => {
const status = {
status: "running",
};
res.send(status);
});
/**
* @openapi
* /builds:
* get:
* description: Get first 10 builds meeting critera in query parameters.
* Get your builds by providing your user id as parameter.
* By default, returning the 10 most recent builds.
* parameters:
* - in: query
* name: author
* schema:
* type: string
* description: The author's user id
* - in: query
* name: civ
* schema:
* type: string
* description: 3 digit civ identifier to filter per civ (ABB, AYY, BYZ, CHI, DEL, ENG, FRE, HRE, JAP, JDA, MAL, MON, DRA, OTT, RUS, ZXL)
* - in: query
* name: orderBy
* schema:
* type: string
* description: The desired order (You may sort by score, timeCreated, views, likes)
* - in: query
* name: overlay
* schema:
* type: boolean
* description: Set to true when you want the overlay tool JSON
* responses:
* 200:
* description: Returns build order(s).
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/build'
*/
app.get('/builds', (req, res) => getAll(req, res))
/**
* @openapi
* /builds/{buildId}:
* get:
* description: Get build by id or error when specified build order is not found.
* parameters:
* - in: path
* name: buildId
* schema:
* type: string
* description: The build order id
* - in: query
* name: overlay
* schema:
* type: boolean
* description: Set to true when you want the overlay tool JSON
* responses:
* 200:
* description: Returns build order(s).
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/build'
*/
app.get('/builds/:buildId', (req, res) => getById(req, res))
/**
* @openapi
* /favorites/{userId}:
* get:
* description: Get your first 10 favorites liked by the referred user and meeting filter and sort crietria.
* By default, returning the 10 most recent builds.
* parameters:
* - in: path
* name: userId
* schema:
* type: string
* description: The author's user id
* - in: query
* name: civ
* schema:
* type: string
* description: 3 digit civ identifier to filter per civ (ABB, AYY, BYZ, CHI, DEL, ENG, FRE, HRE, JAP, JDA, MAL, MON, DRA, OTT, RUS, ZXL)
* - in: query
* name: orderBy
* schema:
* type: string
* description: The desired order (You may sort by score, timeCreated, views, likes)
* - in: query
* name: overlay
* schema:
* type: boolean
* description: Set to true when you want the overlay tool JSON
* responses:
* 200:
* description: Returns build order(s).
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/build'
*/
app.get('/favorites/:userId', (req, res) => getFavorites(req, res))
swagger(app);
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log("Listening on port", port);
});