Skip to content

Commit 4d43cf5

Browse files
committed
enable local development to serve open-api docs
1 parent b6e5e39 commit 4d43cf5

File tree

4 files changed

+92
-5
lines changed

4 files changed

+92
-5
lines changed

common/openapi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: 3.0.4
1+
openapi: 3.1.0
22
info:
33
title: p5.js Web Editor - 1.11.10
44
description: |-
@@ -15,7 +15,7 @@ externalDocs:
1515
servers:
1616
- url: https://editor.p5js.org
1717
description: Production server
18-
- url: http://locationhost:8000
18+
- url: http://localhost:8000
1919
description: Location development server
2020
tags:
2121
- name: Auth

package-lock.json

Lines changed: 78 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
"@types/nodemailer": "^7.0.1",
145145
"@types/nodemailer-mailgun-transport": "^1.4.6",
146146
"@types/passport": "^1.0.17",
147-
"@types/passport": "^1.0.17",
148147
"@types/react": "^16.14.0",
149148
"@types/react-dom": "^16.9.25",
150149
"@types/react-router-dom": "^5.3.3",
@@ -306,10 +305,12 @@
306305
"stacktrace-js": "^2.0.2",
307306
"styled-components": "^5.3.0",
308307
"styled-theming": "^2.2.0",
308+
"swagger-ui-express": "^5.0.1",
309309
"url": "^0.11.0",
310310
"uuid": "^8.3.2",
311311
"webpack": "^5.94.0",
312312
"webpack-dev-middleware": "^5.3.4",
313-
"xhr": "^2.6.0"
313+
"xhr": "^2.6.0",
314+
"yamljs": "^0.3.0"
314315
}
315316
}

server/server.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ import passport from 'passport';
99
import path from 'path';
1010
import basicAuth from 'express-basic-auth';
1111

12+
// Swagger Open Api requirements:
13+
import swaggerUi from 'swagger-ui-express';
14+
import YAML from 'yamljs';
15+
1216
// Webpack Requirements
1317
import webpack from 'webpack';
1418
import webpackDevMiddleware from 'webpack-dev-middleware';
1519
import webpackHotMiddleware from '@gatsbyjs/webpack-hot-middleware';
20+
1621
import config from '../webpack/config.dev';
1722

1823
// Import all required modules
@@ -32,6 +37,7 @@ import { renderIndex } from './views/index';
3237
import { get404Sketch } from './views/404Page';
3338

3439
const app = new Express();
40+
const swaggerDocument = YAML.load('./common/openapi.yaml');
3541

3642
app.get('/health', (req, res) => res.json({ success: true }));
3743

@@ -55,6 +61,9 @@ if (process.env.NODE_ENV === 'development') {
5561
})
5662
);
5763
app.use(webpackHotMiddleware(compiler, { log: false }));
64+
65+
// Show swagger openapi docs in local development only?
66+
app.use('/open-api', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
5867
}
5968

6069
const mongoConnectionString = process.env.MONGO_URL;

0 commit comments

Comments
 (0)