Last active
August 29, 2015 14:04
-
-
Save internetsadboy/8b36ac829eadd214266e to your computer and use it in GitHub Desktop.
swaggerize-express example from docs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "apiVersion": "0.0.1", | |
| "swaggerVersion": "1.2", | |
| "apis": [ | |
| { | |
| "path": "/foo", | |
| "description": "test foo.js" | |
| } | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| var http = require('http'); | |
| var express = require('express'); | |
| var swaggerize = require('swaggerize-express'); | |
| var app, server, swagger, port; | |
| app = express(); | |
| server = http.createServer(app); | |
| swagger = swaggerize({ | |
| api: require('./api.json'), | |
| docs: '/api-docs', | |
| handlers: './handlers' | |
| }); | |
| app.use(swagger); | |
| port = process.env.PORT || 8000; | |
| server.listen(port, 'localhost', function () { | |
| swagger.setUrl('http://' + server.address().address + ':' + server.address().port); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| handlers | |
| - foo.js | |
| api.json | |
| app.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // handlers/foo.js | |
| module.exports = { | |
| get: function(req, reply) { | |
| reply('foo\n'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment