@@ -12,6 +12,9 @@ import logger from "./services/log";
1212import { createUser , findByEmail } from "./user/queries" ;
1313import { Apikey , User } from "@medialit/models" ;
1414import { createApiKey } from "./apikey/queries" ;
15+ import swaggerUi from "swagger-ui-express" ;
16+ import swaggerOutput from "./swagger_output.json" ;
17+
1518import { spawn } from "child_process" ;
1619import { cleanupTUSUploads } from "./tus/cleanup" ;
1720import { cleanupExpiredTempUploads } from "./media/cleanup" ;
@@ -24,30 +27,88 @@ app.set("trust proxy", process.env.ENABLE_TRUST_PROXY === "true");
2427
2528app . use ( express . json ( ) ) ;
2629
27- app . get ( "/health" , ( req , res ) => {
28- res . status ( 200 ) . json ( {
29- status : "ok" ,
30- uptime : process . uptime ( ) ,
31- } ) ;
32- } ) ;
30+ app . get (
31+ "/health" ,
32+ /*
33+ #swagger.summary = 'Status of the server',
34+ #swagger.description = 'Returns the status of the server and uptime'
35+ #swagger.responses[200] = {
36+ description: "OK",
37+ content: {
38+ "application/json": {
39+ schema: {
40+ type: "object",
41+ properties: {
42+ status: {
43+ type: "string",
44+ example: "ok",
45+ },
46+ uptime: {
47+ type: "number",
48+ example: 12.345,
49+ },
50+ },
51+ },
52+ },
53+ },
54+ }
55+ */
56+ ( req , res ) => {
57+ res . status ( 200 ) . json ( {
58+ status : "ok" ,
59+ uptime : process . uptime ( ) ,
60+ } ) ;
61+ } ,
62+ ) ;
63+
64+ app . get (
65+ "/openapi.json" ,
66+ /* #swagger.ignore = true */
67+ ( req , res ) => {
68+ res . json ( swaggerOutput ) ;
69+ } ,
70+ ) ;
71+
72+ app . use (
73+ "/docs" ,
74+ swaggerUi . serve ,
75+ swaggerUi . setup ( swaggerOutput , {
76+ explorer : true ,
77+ swaggerOptions : {
78+ persistAuthorization : true ,
79+ displayRequestDuration : true ,
80+ docExpansion : "none" ,
81+ defaultModelsExpandDepth : - 1 ,
82+ validatorUrl : null ,
83+ } ,
84+ } ) ,
85+ ) ;
3386
3487app . use ( "/settings/media" , mediaSettingsRoutes ( passport ) ) ;
3588app . use ( "/media/signature" , signatureRoutes ) ;
3689app . use ( "/media" , tusRoutes ) ;
3790app . use ( "/media" , mediaRoutes ) ;
3891
39- app . get ( "/cleanup/temp" , async ( req , res ) => {
40- await cleanupExpiredTempUploads ( ) ;
41- res . status ( 200 ) . json ( {
42- message : "Expired temp uploads cleaned up" ,
43- } ) ;
44- } ) ;
45- app . get ( "/cleanup/tus" , async ( req , res ) => {
46- await cleanupTUSUploads ( ) ;
47- res . status ( 200 ) . json ( {
48- message : "Expired tus uploads cleaned up" ,
49- } ) ;
50- } ) ;
92+ app . get (
93+ "/cleanup/temp" ,
94+ /* #swagger.ignore = true */
95+ async ( req , res ) => {
96+ await cleanupExpiredTempUploads ( ) ;
97+ res . status ( 200 ) . json ( {
98+ message : "Expired temp uploads cleaned up" ,
99+ } ) ;
100+ } ,
101+ ) ;
102+ app . get (
103+ "/cleanup/tus" ,
104+ /* #swagger.ignore = true */
105+ async ( req , res ) => {
106+ await cleanupTUSUploads ( ) ;
107+ res . status ( 200 ) . json ( {
108+ message : "Expired tus uploads cleaned up" ,
109+ } ) ;
110+ } ,
111+ ) ;
51112
52113const port = process . env . PORT || 80 ;
53114
0 commit comments