-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
94 lines (79 loc) · 2.63 KB
/
app.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
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var cors = require('cors')
var express = require('express');
var app = express();
app.use(cors())
app.use(express.json())
// These routes use the main app instance 👇
/**
* Healthcheck
*
* Check that the service is up. If everything is okay, you'll get a 200 OK response.
*
* Otherwise, the request will fail with a 400 error, and a response listing the failed services.
*
* @response status=400 scenario="Service is unhealthy" {"status": "down", "services": {"database": "up", "redis": "down"}}
* @responseField status The status of this API (`up` or `down`).
* @responseField services Map of each downstream service and their status (`up` or `down`).
*/
app.get('/api/healthcheck/:unnecessaryParam?', (req, res) => {
return res.json({
"status": "up",
"services": {
"database": "up",
"redis": "up"
}
});
});
/**
* Nested fields
*
* @group Dummy endpoints
* @bodyParam {object} data required The data
* @bodyParam {string} data.name required A string field.
* @bodyParam {int} data.size A number. Example: 5
* @bodyParam {string[]} data.things An array of strings
* @bodyParam {object[]} data.objects An array of objects
* @bodyParam {string} data.objects[].a A field in the array of objects
* @bodyParam {string} data.objects[].b A field in the array of objects
*/
app.post('/nested', function (req, res) {
return res.json(req.body);
});
/**
* Body content array
*
* @group Dummy endpoints
* @bodyParam {object[]} [] List of items
* @bodyParam {string} [].row_id A unique ID. Example: 700
* @bodyParam {string} [].name required An element name. Example: My item name
*/
app.post('/array-body', (req, res) => {
return res.json(req.body);
});
/**
* File input
*
* @group Dummy endpoints
* @bodyParam {file} the_file required Just a file.
* @bodyParam {object} nested required
* @bodyParam {string} nested._string required A nested string.
* @bodyParam {file} nested._file required A nested file.
*/
app.post('/file-input', (req, res) => {
return res.json(req.body);
});
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// These routes create a new express.Router() instance 👇
var sideProjectsRouter = require('./routes/sideProjects');
app.use('/sideProjects', sideProjectsRouter);
// These routes create a new express instance 👇
var usersRouter = require('./routes/users');
app.use('/users', usersRouter);
module.exports = app;