Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 602bc21

Browse files
committed
Fix #535
1 parent 84297da commit 602bc21

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

server/config/swagger-definition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
},
1818
servers: [
1919
{
20-
url: 'plop/api', // `${config.domain}/api`,
20+
url: 'https://localhost/api', // `${config.domain}/api`,
2121
description: 'This app',
2222
},
2323
],

server/routes.js

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,33 @@ export default app => {
4646
contact: {
4747
name: 'API Support',
4848
url: 'https://www.synapse.org',
49-
email: 'thomas.schaffter@sagebase.org'
49+
email: 'thomas.schaffter@sagebase.org',
5050
},
5151
license: {
5252
name: 'CC BY-NC 3.0',
53-
url: 'https://creativecommons.org/licenses/by-nc/3.0/'
54-
}
53+
url: 'https://creativecommons.org/licenses/by-nc/3.0/',
54+
},
5555
},
56-
servers: [{
57-
url: `${config.domain}/api`,
58-
description: 'This app'
59-
}],
56+
servers: [
57+
{
58+
url: `${config.domain}/api`,
59+
description: 'This app',
60+
},
61+
],
6062
components: {
6163
securitySchemes: {
6264
BearerAuth: {
6365
type: 'http',
6466
scheme: 'bearer',
65-
bearerFormat: 'JWT'
66-
}
67+
bearerFormat: 'JWT',
68+
},
6769
},
6870
responses: {
6971
UnauthorizedError: {
70-
description: 'Access token is missing or invalid'
71-
}
72-
}
73-
}
72+
description: 'Access token is missing or invalid',
73+
},
74+
},
75+
},
7476
};
7577

7678
const swaggerOptions = {
@@ -81,29 +83,29 @@ export default app => {
8183

8284
// options for the swagger docs
8385
var swaggerJSDocOptions = {
84-
swaggerDefinition: swaggerDefinition,
85-
apis: [
86-
'./**/api/**/index.js',
87-
'./**/auth/**/*.js',
88-
'./shared/interfaces/**/*.ts'
89-
// './**/swagger/**/*.ts'
90-
]
86+
swaggerDefinition,
87+
apis: ['./**/api/**/index.js', './**/auth/**/*.js', './shared/interfaces/**/*.ts'],
9188
};
9289

93-
// initialize swagger-jsdoc
94-
const swaggerSpec = swaggerJSDoc(swaggerJSDocOptions);
95-
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec, swaggerOptions));
90+
let swaggerDocument = {};
91+
if (config.env === 'development') {
92+
swaggerDocument = swaggerJSDoc(swaggerJSDocOptions);
93+
} else if (config.env === 'production') {
94+
swaggerDocument = require('../client/swagger.json');
95+
}
9696

97-
// Swagger
98-
// app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
97+
// https://github.com/scottie1984/swagger-ui-express/issues/94
98+
// app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, swaggerOptions));
99+
const swaggerSetup = swaggerUi.setup(swaggerDocument, swaggerOptions);
100+
app.get('/api-docs/index.html', swaggerSetup);
101+
app.use('/api-docs', swaggerUi.serve);
102+
app.get('/api-docs', swaggerSetup);
99103

100104
// All undefined asset or api routes should return a 404
101-
app.route('/:url(api|auth|components|app|bower_components|assets|api-docs)/*')
102-
.get(errors[404]);
105+
app.route('/:url(api|auth|components|app|bower_components|assets|api-docs)/*').get(errors[404]);
103106

104107
// All other routes should redirect to the app.html
105-
app.route('/*')
106-
.get((req, res) => {
107-
res.sendFile(path.resolve(`${app.get('appPath')}/app.html`));
108-
});
108+
app.route('/*').get((req, res) => {
109+
res.sendFile(path.resolve(`${app.get('appPath')}/app.html`));
110+
});
109111
};

0 commit comments

Comments
 (0)