-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (31 loc) · 687 Bytes
/
index.js
File metadata and controls
36 lines (31 loc) · 687 Bytes
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
const restana = require('../../index')
const path = require('path')
const {
SwaggerValidationError,
SwaggerValidator
} = require('restana-swagger-validator')
const app = restana({
errorHandler: (err, req, res) => {
if (err instanceof SwaggerValidationError) {
res.statusCode = err.statusCode
res.send({
message: err.message,
errors: err.errors
})
} else {
res.send(err)
}
}
})
SwaggerValidator(app, path.join(__dirname, '/spec.json'), {
buildResponses: true,
publicApiEndpoint: 'http://localhost:3000'
})
app.get('/pets', (req, res) => {
res.send([{
id: 1,
name: 'Pluto',
tag: 'dog'
}])
})
app.start()