Skip to content

Commit

Permalink
Add route for OpenAPI definition in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesboeufs committed Jun 23, 2016
1 parent c43998a commit 8cb57bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"debug": "^2.2.0",
"express": "^4.13.4",
"iconv-lite": "^0.4.13",
"js-yaml": "^3.6.1",
"lodash": "^4.12.0",
"lunr": "^0.7.1",
"morgan": "^1.7.0",
Expand Down
8 changes: 8 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const dbCommunes = require('./lib/communes').getIndexedDb();
const dbDepartements = require('./lib/departements').getIndexedDb();
const dbRegions = require('./lib/regions').getIndexedDb();
const { pick } = require('lodash');
const yaml = require('js-yaml');
const fs = require('fs');

const openAPIDefinition = yaml.safeLoad(fs.readFileSync(__dirname + '/definition.yml', 'utf8'));

const app = express();
app.use(cors());
Expand Down Expand Up @@ -147,6 +151,10 @@ app.get('/definition.yml', function (req, res) {
res.sendFile(__dirname + '/definition.yml');
});

app.get('/definition.json', function (req, res) {
res.send(openAPIDefinition);
});

const port = process.env.PORT || 5000;

app.listen(port, () => {
Expand Down

0 comments on commit 8cb57bb

Please sign in to comment.