maxserver 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/setup.js +1 -38
- package/src/setupDocs.js +85 -0
- package/templates/src/Tests/hello.js +14 -0
- package/templates/src/Tests/hello.schema.js +27 -0
- package/templates/src/{welcome.js → Tests/welcome.js} +1 -1
- package/templates/src/Tests/welcome.schema.js +17 -0
- package/templates/vscode/tasks.json +14 -7
- package/templates/src/hello.js +0 -14
- package/templates/src/hello.schema.js +0 -36
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
setupJwt,
|
|
7
7
|
setupMongo,
|
|
8
8
|
setupStatic,
|
|
9
|
-
setupDocs,
|
|
10
9
|
setupCookie,
|
|
11
10
|
} from "./setup.js";
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
import { getAddress } from "./getAddress.js";
|
|
14
|
+
import { setupDocs } from "./setupDocs.js";
|
|
15
15
|
import { setupRoutes } from "./setupRoutes.js";
|
|
16
16
|
|
|
17
17
|
|
package/src/setup.js
CHANGED
|
@@ -7,8 +7,7 @@ import cookie from "@fastify/cookie";
|
|
|
7
7
|
import mongodb from "@fastify/mongodb";
|
|
8
8
|
import fastifyStatic from "@fastify/static";
|
|
9
9
|
import helmet from "@fastify/helmet";
|
|
10
|
-
|
|
11
|
-
import apiReference from "@scalar/fastify-api-reference";
|
|
10
|
+
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
export async function setupHelmet(app) {
|
|
@@ -78,42 +77,6 @@ export async function setupJwt(app) {
|
|
|
78
77
|
|
|
79
78
|
|
|
80
79
|
|
|
81
|
-
export async function setupDocs(app) {
|
|
82
|
-
|
|
83
|
-
const info = app.maxserver.openapiInfo || {
|
|
84
|
-
title: "API",
|
|
85
|
-
version: "1.0.0",
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
await app.register(swagger, {
|
|
89
|
-
openapi: {
|
|
90
|
-
info,
|
|
91
|
-
// OpenAPI 3.x: securitySchemes must be defined globally here not per route
|
|
92
|
-
// Routes only add `security: [...]` that references these scheme names
|
|
93
|
-
components: {
|
|
94
|
-
securitySchemes: {
|
|
95
|
-
bearerAuth: { type: "http", scheme: "bearer" },
|
|
96
|
-
cookieAuth: { type: "apiKey", in: "cookie", name: "token" },
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
app.get("/openapi.json", {}, () => app.swagger());
|
|
104
|
-
|
|
105
|
-
if (app.maxserver.docs !== false)
|
|
106
|
-
await app.register(apiReference, { routePrefix: "/docs", openapi: true });
|
|
107
|
-
|
|
108
|
-
app.addHook("onRoute", (route) => {
|
|
109
|
-
const auth = route.config?.auth;
|
|
110
|
-
if (!auth) return;
|
|
111
|
-
route.schema ||= {};
|
|
112
|
-
route.schema.security ||= [{ bearerAuth: [] }, { cookieAuth: [] }];
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
80
|
|
|
118
81
|
export async function setupStatic(app) {
|
|
119
82
|
const dir = app.maxserver.static;
|
package/src/setupDocs.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import swagger from "@fastify/swagger";
|
|
2
|
+
import apiReference from "@scalar/fastify-api-reference";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export async function setupDocs(app) {
|
|
6
|
+
|
|
7
|
+
const info = app.maxserver.openapiInfo || {
|
|
8
|
+
title: "API",
|
|
9
|
+
version: "1.0.0",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
await app.register(swagger, {
|
|
13
|
+
openapi: {
|
|
14
|
+
info,
|
|
15
|
+
// OpenAPI 3.x: securitySchemes must be defined globally here not per route
|
|
16
|
+
// Routes only add `security: [...]` that references these scheme names
|
|
17
|
+
components: {
|
|
18
|
+
securitySchemes: {
|
|
19
|
+
bearerAuth: { type: "http", scheme: "bearer" },
|
|
20
|
+
cookieAuth: { type: "apiKey", in: "cookie", name: "token" },
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
// This replaces your manual app.get line
|
|
25
|
+
exposeRoute: true,
|
|
26
|
+
routePrefix: "/openapi.json"
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
//app.get("/openapi.json", {}, () => app.swagger());
|
|
32
|
+
|
|
33
|
+
if (app.maxserver.docs !== false)
|
|
34
|
+
await app.register(apiReference, { routePrefix: "/docs", openapi: true });
|
|
35
|
+
|
|
36
|
+
app.addHook("onRoute", (route) => {
|
|
37
|
+
const auth = route.config?.auth;
|
|
38
|
+
if (!auth) return;
|
|
39
|
+
route.schema ||= {};
|
|
40
|
+
route.schema.security ||= [{ bearerAuth: [] }, { cookieAuth: [] }];
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
export default {
|
|
48
|
+
summary: "OpenAPI Documentation",
|
|
49
|
+
description: "Returns the OpenAPI 3.0.0 specification for the entire API.",
|
|
50
|
+
tags: ["Documentation"],
|
|
51
|
+
response: {
|
|
52
|
+
200: {
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: {
|
|
55
|
+
openapi: {
|
|
56
|
+
type: "string",
|
|
57
|
+
example: "3.0.0"
|
|
58
|
+
},
|
|
59
|
+
info: {
|
|
60
|
+
type: "object",
|
|
61
|
+
properties: {
|
|
62
|
+
title: {
|
|
63
|
+
type: "string",
|
|
64
|
+
example: "maxserver API"
|
|
65
|
+
},
|
|
66
|
+
version: {
|
|
67
|
+
type: "string",
|
|
68
|
+
example: "1.0.0"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
required: ["title", "version"]
|
|
72
|
+
},
|
|
73
|
+
paths: {
|
|
74
|
+
type: "object",
|
|
75
|
+
example: {}
|
|
76
|
+
},
|
|
77
|
+
components: {
|
|
78
|
+
type: "object",
|
|
79
|
+
example: {}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
required: ["openapi", "info", "paths"]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
summary: "Test post hello",
|
|
3
|
+
description: "Receives a name in the body and returns a personalized hello message.",
|
|
4
|
+
tags: ["Tests"],
|
|
5
|
+
body: {
|
|
6
|
+
type: "object",
|
|
7
|
+
properties: {
|
|
8
|
+
name: {
|
|
9
|
+
type: "string",
|
|
10
|
+
example: "John Doe"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
required: ["name"]
|
|
14
|
+
},
|
|
15
|
+
response: {
|
|
16
|
+
200: {
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
message: {
|
|
20
|
+
type: "string",
|
|
21
|
+
example: "Hello John Doe again 🙋♂️"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
required: ["message"]
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
summary: "Test get welcome",
|
|
3
|
+
description: "Returns a friendly welcome message to verify the server is operational.",
|
|
4
|
+
tags: ["Tests"],
|
|
5
|
+
response: {
|
|
6
|
+
200: {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {
|
|
9
|
+
message: {
|
|
10
|
+
type: "string",
|
|
11
|
+
example: "Weclome to maxserver 😉 - Updated"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
required: ["message"]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// Comment task in to autostart server on dir open
|
|
2
|
-
/*
|
|
3
|
-
|
|
4
|
-
|
|
5
2
|
{
|
|
6
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
7
4
|
"tasks": [
|
|
8
5
|
{
|
|
9
6
|
"label": "devserver 📟",
|
|
@@ -16,8 +13,18 @@
|
|
|
16
13
|
"runOptions": {
|
|
17
14
|
"runOn": "folderOpen"
|
|
18
15
|
}
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"label": "openBrowser",
|
|
19
|
+
"type": "shell",
|
|
20
|
+
"command": "sleep 1; open http://localhost:3000/docs",
|
|
21
|
+
"presentation": {
|
|
22
|
+
"reveal": "never",
|
|
23
|
+
"panel": "shared"
|
|
24
|
+
},
|
|
25
|
+
"runOptions": {
|
|
26
|
+
"runOn": "folderOpen"
|
|
27
|
+
}
|
|
19
28
|
}
|
|
20
29
|
]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
*/
|
|
30
|
+
}
|
package/templates/src/hello.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
|
|
3
|
-
// These 3 fields are for the documentation
|
|
4
|
-
// Not must have, but your auto generated documentation will be great
|
|
5
|
-
|
|
6
|
-
tags: ["Test"],
|
|
7
|
-
summary: "Post hello",
|
|
8
|
-
description: "Accepts a name and returns a greeting.",
|
|
9
|
-
|
|
10
|
-
body: {
|
|
11
|
-
type: "object",
|
|
12
|
-
required: ["name"],
|
|
13
|
-
properties: {
|
|
14
|
-
name: {
|
|
15
|
-
type: "string",
|
|
16
|
-
example: "Max",
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
response: {
|
|
22
|
-
200: {
|
|
23
|
-
type: "object",
|
|
24
|
-
properties: {
|
|
25
|
-
message: {
|
|
26
|
-
type: "string",
|
|
27
|
-
example: "Hello Max",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// Hint - You don't need to write these ourself
|
|
35
|
-
// Just ask chat gpt or gemini to generate them
|
|
36
|
-
// In docs you will find little instruction for it
|