-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (43 loc) · 1.83 KB
/
index.js
File metadata and controls
56 lines (43 loc) · 1.83 KB
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
'use strict';
const fs = require('fs'),
path = require('path'),
http = require('http'),
app = require('connect')(),
jsyaml = require('js-yaml'),
swaggerTools = require('swagger-tools'),
swaggerSenecaRouter = require('swagger-seneca-router');
const serverPort = 8888;
const spec = fs.readFileSync(path.join(__dirname, '/spec/petstore-simple.yaml'), 'utf8');
const swaggerDoc = jsyaml.safeLoad(spec);
// Initialize the Swagger middleware
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
require('seneca')()
.use('entity')
.use('mesh')
.ready( function() {
//TODO add Auth support and harden App.
app.use(middleware.swaggerMetadata());
app.use(middleware.swaggerValidator());
app.use(middleware.swaggerUi());
app.use( swaggerSenecaRouter( {
senecaClient : this,
patternNotFoundMode : 'error',
matchXSenecaPatternsOnly : true,
defaultErrorCode : 500,
senecaErrorMode : {
'default' : 'error',
'act_not_found' : 'next',
'no-current-target' : 'jsonic:{body:{errCode:3322,errMessage:"Oops, our servers appear to be down!"}}'
}
} ) );
app.use( function (req, res, next) {
res.writeHead(404, {});
res.end( 'Not found');
});
// Start the server
http.createServer(app).listen(serverPort, function () {
console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort);
console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort);
});
});
});