[mirotalk] - add swagger ui for api docs

This commit is contained in:
Miroslav Pejic
2021-07-06 12:35:06 +02:00
parent 1212b82dc9
commit d0f22e228e
4 changed files with 77 additions and 6 deletions
+7 -4
View File
@@ -138,13 +138,16 @@ docker-compose down
## API
The `response` will give you a `entrypoint / Room URL` for `your meeting`.
The `response` will give you a `entrypoint / Room URL` for `your meeting`, where `authorization: API_KEY_SECRET`.
```bash
curl -X POST "http://localhost:3000/api/v1/meeting" -H "authorization: YourApiKeySecret" -H "Content-Type: application/json" -d "{ \"title\": \"Mirotalk GET meeting\"}"
curl -X POST "https://mirotalk.up.railway.app/api/v1/meeting" -H "authorization: mirotalk_default_secret" -H "Content-Type: application/json" -d "{ \"title\": \"Mirotalk GET meeting\"}"
curl -X POST "https://mirotalk.herokuapp.com/api/v1/meeting" -H "authorization: mirotalk_default_secret" -H "Content-Type: application/json" -d "{ \"title\": \"Mirotalk GET meeting\"}"
curl -X POST "http://localhost:3000/api/v1/meeting" -H "authorization: mirotalk_default_secret" -H "Content-Type: application/json"
curl -X POST "https://mirotalk.up.railway.app/api/v1/meeting" -H "authorization: mirotalk_default_secret" -H "Content-Type: application/json"
curl -X POST "https://mirotalk.herokuapp.com/api/v1/meeting" -H "authorization: mirotalk_default_secret" -H "Content-Type: application/json"
```
## API Documentation
The server exposes a [swagger](https://swagger.io/) document at http://localhost:3000/api/v1/docs. Or you can check it out live on [railway](https://mirotalk.up.railway.app/api/v1/docs) or [heroku](https://mirotalk.herokuapp.com/api/v1/docs).
---
+47
View File
@@ -0,0 +1,47 @@
swagger: "2.0"
info:
title: Mirotalk API
description: API description for external applications that integrates with Mirotalk.
version: 1.0.0
basePath: /api/v1
schemes:
- https
- http
paths:
/meeting:
post:
tags:
- "meeting"
summary: "Create meeting"
description: "Create meeting"
consumes:
- "application/json"
produces:
- "application/json"
security:
- secretApiKey: []
responses:
"200":
description: "Meeting created"
schema:
$ref: "#/definitions/MeetingResponse"
"403":
description: "Unauthorized!"
securityDefinitions:
secretApiKey:
type: "apiKey"
name: "authorization"
in: "header"
description: "Format like this: authorization: {API_KEY_SECRET}"
definitions:
MeetingResponse:
type: "object"
properties:
meeting:
type: "string"
+3 -1
View File
@@ -19,6 +19,8 @@
"dotenv": "^10.0.0",
"express": "^4.17.1",
"ngrok": "^4.0.1",
"socket.io": "^4.1.2"
"socket.io": "^4.1.2",
"swagger-ui-express": "^4.1.6",
"yamljs": "^0.3.0"
}
}
+20 -1
View File
@@ -13,6 +13,8 @@ dependencies: {
express : https://www.npmjs.com/package/express
ngrok : https://www.npmjs.com/package/ngrok
socket.io : https://www.npmjs.com/package/socket.io
swagger : https://www.npmjs.com/package/swagger-ui-express
yamljs : https://www.npmjs.com/package/yamljs
}
Mirotalk Signaling Server
@@ -47,10 +49,15 @@ const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server().listen(server);
const ngrok = require("ngrok");
const yamlJS = require("yamljs");
const swaggerUi = require("swagger-ui-express");
const swaggerDocument = yamlJS.load(__dirname + "/api/swagger.yaml");
const apiBasePath = "/api/v1";
let API_KEY_SECRET = process.env.API_KEY_SECRET || "mirotalk_default_secret";
let PORT = process.env.PORT || 3000; // signalingServerPort
let localHost = "http://localhost:" + PORT; // http
let api_docs = localHost + apiBasePath + "/docs"; // api docs
let channels = {}; // collect channels
let sockets = {}; // collect sockets
let peers = {}; // collect peers info grp by channels
@@ -129,8 +136,18 @@ app.get("/join/*", (req, res) => {
/**
MIROTALK API v1
The response will give you a entrypoint / Room URL for your meeting.
For api docs we use: https://swagger.io/
*/
app.post(["/api/v1/meeting"], (req, res) => {
// api docs
app.use(
apiBasePath + "/docs",
swaggerUi.serve,
swaggerUi.setup(swaggerDocument)
);
// request meeting room endpoint
app.post([apiBasePath + "/meeting"], (req, res) => {
// check if user was authorized for the api call
let authorization = req.headers.authorization;
if (authorization != API_KEY_SECRET) {
@@ -218,6 +235,7 @@ async function ngrokStart() {
logme("settings", {
http: localHost,
https: tunnelHttps,
api_docs: api_docs,
api_key_secret: API_KEY_SECRET,
iceServers: iceServers,
ngrok: {
@@ -255,6 +273,7 @@ server.listen(PORT, null, () => {
// server settings
logme("settings", {
http: localHost,
api_docs: api_docs,
api_key_secret: API_KEY_SECRET,
iceServers: iceServers,
});