@seip/bluebird-js 0.0.1 → 0.1.0
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/.env_example +53 -53
- package/AGENTS.md +426 -403
- package/LICENSE +1 -1
- package/README.md +292 -285
- package/app/routes/api.js +50 -50
- package/app/routes/web.js +55 -53
- package/app/views/about.js +63 -0
- package/app/views/dashboard.js +147 -0
- package/app/views/index.js +80 -0
- package/app/views/layouts/main/view.js +81 -0
- package/app/views/legal/terms.html +19 -0
- package/app/views/login.js +80 -0
- package/core/app.d.ts +18 -18
- package/core/app.js +684 -644
- package/core/auth.d.ts +13 -13
- package/core/auth.js +326 -326
- package/core/cache.d.ts +17 -17
- package/core/cache.js +475 -475
- package/core/cli/doctor.js +287 -287
- package/core/cli/ecosystem.js +162 -162
- package/core/cli/init.js +779 -779
- package/core/cli/migrate.js +541 -541
- package/core/cli/model.js +66 -66
- package/core/cli/nginx.js +199 -199
- package/core/cli/route.js +120 -120
- package/core/cli/view.js +55 -36
- package/core/config.d.ts +3 -3
- package/core/config.js +111 -111
- package/core/csrf.d.ts +3 -3
- package/core/csrf.js +114 -114
- package/core/database.d.ts +15 -15
- package/core/database.js +636 -636
- package/core/debug.d.ts +3 -3
- package/core/debug.js +249 -249
- package/core/hash.d.ts +3 -3
- package/core/hash.js +194 -194
- package/core/html.d.ts +42 -0
- package/core/html.js +217 -0
- package/core/index.d.ts +1176 -1071
- package/core/logger.d.ts +3 -3
- package/core/logger.js +127 -124
- package/core/middleware.d.ts +3 -3
- package/core/middleware.js +28 -28
- package/core/model.d.ts +19 -19
- package/core/model.js +600 -600
- package/core/queue.d.ts +13 -13
- package/core/queue.js +172 -172
- package/core/ratelimit.d.ts +3 -3
- package/core/ratelimit.js +145 -145
- package/core/redis.d.ts +21 -21
- package/core/redis.js +230 -230
- package/core/render-cache.js +212 -0
- package/core/render.d.ts +3 -3
- package/core/render.js +199 -555
- package/core/router.d.ts +3 -3
- package/core/router.js +171 -171
- package/core/seo.d.ts +3 -3
- package/core/seo.js +106 -106
- package/core/swagger.d.ts +3 -3
- package/core/swagger.js +60 -60
- package/core/upload.d.ts +13 -13
- package/core/upload.js +102 -102
- package/core/util/colors.js +82 -82
- package/core/validate.d.ts +15 -15
- package/core/validate.js +364 -364
- package/core/view-loader.js +162 -0
- package/core/vite.d.ts +3 -3
- package/core/vite.js +145 -145
- package/core/ws.d.ts +13 -13
- package/core/ws.js +245 -245
- package/index.js +18 -18
- package/jsconfig.json +15 -15
- package/package.json +85 -86
- package/production.md +273 -273
- package/public/css/bluebird.min.css +1 -1
- package/public/js/bluebird-client.js +1780 -1662
- package/public/js/bluebird.min.js +1072 -1072
- package/app/views/about.html +0 -161
- package/app/views/dashboard.html +0 -140
- package/app/views/index.html +0 -150
- package/app/views/login.html +0 -144
package/core/router.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Router, RouterOptions } from "./index.js";
|
|
2
|
-
export default Router;
|
|
3
|
-
export { Router, RouterOptions };
|
|
1
|
+
import { Router, RouterOptions } from "./index.js";
|
|
2
|
+
export default Router;
|
|
3
|
+
export { Router, RouterOptions };
|
package/core/router.js
CHANGED
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import Config from "./config.js";
|
|
3
|
-
import Seo from "./seo.js";
|
|
4
|
-
|
|
5
|
-
const props = Config.props();
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Wraps route handlers to automatically catch async rejections and forward them to next(err).
|
|
9
|
-
* @param {Function} fn - Handler function.
|
|
10
|
-
* @returns {Function} Wrapped handler.
|
|
11
|
-
*/
|
|
12
|
-
function wrapAsync(fn) {
|
|
13
|
-
if (typeof fn !== "function") return fn;
|
|
14
|
-
return (req, res, next) => {
|
|
15
|
-
try {
|
|
16
|
-
const result = fn(req, res, next);
|
|
17
|
-
if (result && typeof result.catch === "function") {
|
|
18
|
-
result.catch(next);
|
|
19
|
-
}
|
|
20
|
-
} catch (err) {
|
|
21
|
-
next(err);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Router wrapper class for handling Express routing logic.
|
|
28
|
-
* When created with { seo: true }, all GET routes registered on this router
|
|
29
|
-
* are automatically included in the generated sitemap.xml and robots.txt.
|
|
30
|
-
*/
|
|
31
|
-
class Router {
|
|
32
|
-
/**
|
|
33
|
-
* Creates a new Router instance.
|
|
34
|
-
* @param {string} [path="/"] - The base path for this router.
|
|
35
|
-
* @param {Object} [options={}] - Router configuration options.
|
|
36
|
-
* @param {boolean} [options.seo=false] - When true, GET routes on this router are included in sitemap/robots.txt.
|
|
37
|
-
* @param {string[]} [options.languages=[]] - Language prefixes for SEO route generation (e.g., ["en", "es"]).
|
|
38
|
-
* @example
|
|
39
|
-
* const router = new Router("/", { seo: true, languages: ["en", "es"] });
|
|
40
|
-
* router.get("/", (req, res) => {
|
|
41
|
-
* Render.send(res, "index", { title: "Home" });
|
|
42
|
-
* });
|
|
43
|
-
*/
|
|
44
|
-
constructor(path = "/", options = {}) {
|
|
45
|
-
this.router = express.Router();
|
|
46
|
-
this.path = path;
|
|
47
|
-
this._seo = options.seo ?? false;
|
|
48
|
-
this._languages = options.languages || [];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Registers a middleware on this router.
|
|
53
|
-
* @param {...Function} middleware - Middleware functions.
|
|
54
|
-
* @example
|
|
55
|
-
* router.use(Auth.protect());
|
|
56
|
-
* router.use(App.helmet());
|
|
57
|
-
*/
|
|
58
|
-
use(...middleware) {
|
|
59
|
-
const handlers = middleware.map(wrapAsync);
|
|
60
|
-
this.router.use(...handlers);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Registers a GET route handler.
|
|
65
|
-
* If this router was created with { seo: true }, the route path is automatically
|
|
66
|
-
* registered for sitemap.xml and robots.txt generation.
|
|
67
|
-
* @param {string|RegExp} path - The relative path for the GET route.
|
|
68
|
-
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
69
|
-
* @example
|
|
70
|
-
* router.get("/about", (req, res) => {
|
|
71
|
-
* Render.send(res, "about", { title: "About Us" });
|
|
72
|
-
* });
|
|
73
|
-
*/
|
|
74
|
-
get(path, ...callback) {
|
|
75
|
-
if (this._seo && typeof path === "string") {
|
|
76
|
-
Seo.registerRoute(this.path, path, this._languages);
|
|
77
|
-
}
|
|
78
|
-
if (path === "/*" || path === "*") {
|
|
79
|
-
path = /.*/;
|
|
80
|
-
}
|
|
81
|
-
const handlers = callback.map(wrapAsync);
|
|
82
|
-
this.router.get(path, ...handlers);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Registers a POST route handler.
|
|
87
|
-
* @param {string} path - The relative path for the POST route.
|
|
88
|
-
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
89
|
-
* @example
|
|
90
|
-
* router.post("/users", (req, res) => {
|
|
91
|
-
* res.json({ message: "User created successfully" })
|
|
92
|
-
* })
|
|
93
|
-
*/
|
|
94
|
-
post(path, ...callback) {
|
|
95
|
-
if (path === "/*" || path === "*") {
|
|
96
|
-
path = /.*/;
|
|
97
|
-
}
|
|
98
|
-
const handlers = callback.map(wrapAsync);
|
|
99
|
-
this.router.post(path, ...handlers);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Registers a PUT route handler.
|
|
104
|
-
* @param {string} path - The relative path for the PUT route.
|
|
105
|
-
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
106
|
-
* @example
|
|
107
|
-
* router.put("/users/:id", (req, res) => {
|
|
108
|
-
* res.json({ message: "User updated successfully" })
|
|
109
|
-
* })
|
|
110
|
-
*/
|
|
111
|
-
put(path, ...callback) {
|
|
112
|
-
const handlers = callback.map(wrapAsync);
|
|
113
|
-
this.router.put(path, ...handlers);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Registers a DELETE route handler.
|
|
118
|
-
* @param {string} path - The relative path for the DELETE route.
|
|
119
|
-
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
120
|
-
* @example
|
|
121
|
-
* router.delete("/users/:id", (req, res) => {
|
|
122
|
-
* res.json({ message: "User deleted successfully" })
|
|
123
|
-
* })
|
|
124
|
-
*/
|
|
125
|
-
delete(path, ...callback) {
|
|
126
|
-
const handlers = callback.map(wrapAsync);
|
|
127
|
-
this.router.delete(path, ...handlers);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Registers a PATCH route handler.
|
|
132
|
-
* @param {string} path - The relative path for the PATCH route.
|
|
133
|
-
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
134
|
-
* @example
|
|
135
|
-
* router.patch("/users/:id", (req, res) => {
|
|
136
|
-
* res.json({ message: "User patched successfully" })
|
|
137
|
-
* })
|
|
138
|
-
*/
|
|
139
|
-
patch(path, ...callback) {
|
|
140
|
-
const handlers = callback.map(wrapAsync);
|
|
141
|
-
this.router.patch(path, ...handlers);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Registers an OPTIONS route handler.
|
|
146
|
-
* @param {string} path - The relative path for the OPTIONS route.
|
|
147
|
-
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
148
|
-
*/
|
|
149
|
-
options(path, ...callback) {
|
|
150
|
-
const handlers = callback.map(wrapAsync);
|
|
151
|
-
this.router.options(path, ...handlers);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Returns the underlying Express router instance.
|
|
156
|
-
* @returns {import('express').Router}
|
|
157
|
-
*/
|
|
158
|
-
getRouter() {
|
|
159
|
-
return this.router;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Returns the base path associated with this router.
|
|
164
|
-
* @returns {string}
|
|
165
|
-
*/
|
|
166
|
-
getPath() {
|
|
167
|
-
return this.path;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
export { Router };
|
|
171
|
-
export default Router;
|
|
1
|
+
import express from "express";
|
|
2
|
+
import Config from "./config.js";
|
|
3
|
+
import Seo from "./seo.js";
|
|
4
|
+
|
|
5
|
+
const props = Config.props();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Wraps route handlers to automatically catch async rejections and forward them to next(err).
|
|
9
|
+
* @param {Function} fn - Handler function.
|
|
10
|
+
* @returns {Function} Wrapped handler.
|
|
11
|
+
*/
|
|
12
|
+
function wrapAsync(fn) {
|
|
13
|
+
if (typeof fn !== "function") return fn;
|
|
14
|
+
return (req, res, next) => {
|
|
15
|
+
try {
|
|
16
|
+
const result = fn(req, res, next);
|
|
17
|
+
if (result && typeof result.catch === "function") {
|
|
18
|
+
result.catch(next);
|
|
19
|
+
}
|
|
20
|
+
} catch (err) {
|
|
21
|
+
next(err);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Router wrapper class for handling Express routing logic.
|
|
28
|
+
* When created with { seo: true }, all GET routes registered on this router
|
|
29
|
+
* are automatically included in the generated sitemap.xml and robots.txt.
|
|
30
|
+
*/
|
|
31
|
+
class Router {
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new Router instance.
|
|
34
|
+
* @param {string} [path="/"] - The base path for this router.
|
|
35
|
+
* @param {Object} [options={}] - Router configuration options.
|
|
36
|
+
* @param {boolean} [options.seo=false] - When true, GET routes on this router are included in sitemap/robots.txt.
|
|
37
|
+
* @param {string[]} [options.languages=[]] - Language prefixes for SEO route generation (e.g., ["en", "es"]).
|
|
38
|
+
* @example
|
|
39
|
+
* const router = new Router("/", { seo: true, languages: ["en", "es"] });
|
|
40
|
+
* router.get("/", (req, res) => {
|
|
41
|
+
* Render.send(res, "index", { title: "Home" });
|
|
42
|
+
* });
|
|
43
|
+
*/
|
|
44
|
+
constructor(path = "/", options = {}) {
|
|
45
|
+
this.router = express.Router();
|
|
46
|
+
this.path = path;
|
|
47
|
+
this._seo = options.seo ?? false;
|
|
48
|
+
this._languages = options.languages || [];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Registers a middleware on this router.
|
|
53
|
+
* @param {...Function} middleware - Middleware functions.
|
|
54
|
+
* @example
|
|
55
|
+
* router.use(Auth.protect());
|
|
56
|
+
* router.use(App.helmet());
|
|
57
|
+
*/
|
|
58
|
+
use(...middleware) {
|
|
59
|
+
const handlers = middleware.map(wrapAsync);
|
|
60
|
+
this.router.use(...handlers);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Registers a GET route handler.
|
|
65
|
+
* If this router was created with { seo: true }, the route path is automatically
|
|
66
|
+
* registered for sitemap.xml and robots.txt generation.
|
|
67
|
+
* @param {string|RegExp} path - The relative path for the GET route.
|
|
68
|
+
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
69
|
+
* @example
|
|
70
|
+
* router.get("/about", (req, res) => {
|
|
71
|
+
* Render.send(res, "about", { title: "About Us" });
|
|
72
|
+
* });
|
|
73
|
+
*/
|
|
74
|
+
get(path, ...callback) {
|
|
75
|
+
if (this._seo && typeof path === "string") {
|
|
76
|
+
Seo.registerRoute(this.path, path, this._languages);
|
|
77
|
+
}
|
|
78
|
+
if (path === "/*" || path === "*") {
|
|
79
|
+
path = /.*/;
|
|
80
|
+
}
|
|
81
|
+
const handlers = callback.map(wrapAsync);
|
|
82
|
+
this.router.get(path, ...handlers);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Registers a POST route handler.
|
|
87
|
+
* @param {string} path - The relative path for the POST route.
|
|
88
|
+
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
89
|
+
* @example
|
|
90
|
+
* router.post("/users", (req, res) => {
|
|
91
|
+
* res.json({ message: "User created successfully" })
|
|
92
|
+
* })
|
|
93
|
+
*/
|
|
94
|
+
post(path, ...callback) {
|
|
95
|
+
if (path === "/*" || path === "*") {
|
|
96
|
+
path = /.*/;
|
|
97
|
+
}
|
|
98
|
+
const handlers = callback.map(wrapAsync);
|
|
99
|
+
this.router.post(path, ...handlers);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Registers a PUT route handler.
|
|
104
|
+
* @param {string} path - The relative path for the PUT route.
|
|
105
|
+
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
106
|
+
* @example
|
|
107
|
+
* router.put("/users/:id", (req, res) => {
|
|
108
|
+
* res.json({ message: "User updated successfully" })
|
|
109
|
+
* })
|
|
110
|
+
*/
|
|
111
|
+
put(path, ...callback) {
|
|
112
|
+
const handlers = callback.map(wrapAsync);
|
|
113
|
+
this.router.put(path, ...handlers);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Registers a DELETE route handler.
|
|
118
|
+
* @param {string} path - The relative path for the DELETE route.
|
|
119
|
+
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
120
|
+
* @example
|
|
121
|
+
* router.delete("/users/:id", (req, res) => {
|
|
122
|
+
* res.json({ message: "User deleted successfully" })
|
|
123
|
+
* })
|
|
124
|
+
*/
|
|
125
|
+
delete(path, ...callback) {
|
|
126
|
+
const handlers = callback.map(wrapAsync);
|
|
127
|
+
this.router.delete(path, ...handlers);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Registers a PATCH route handler.
|
|
132
|
+
* @param {string} path - The relative path for the PATCH route.
|
|
133
|
+
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
134
|
+
* @example
|
|
135
|
+
* router.patch("/users/:id", (req, res) => {
|
|
136
|
+
* res.json({ message: "User patched successfully" })
|
|
137
|
+
* })
|
|
138
|
+
*/
|
|
139
|
+
patch(path, ...callback) {
|
|
140
|
+
const handlers = callback.map(wrapAsync);
|
|
141
|
+
this.router.patch(path, ...handlers);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Registers an OPTIONS route handler.
|
|
146
|
+
* @param {string} path - The relative path for the OPTIONS route.
|
|
147
|
+
* @param {...Function} callback - One or more handler functions (middlewares and controller).
|
|
148
|
+
*/
|
|
149
|
+
options(path, ...callback) {
|
|
150
|
+
const handlers = callback.map(wrapAsync);
|
|
151
|
+
this.router.options(path, ...handlers);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Returns the underlying Express router instance.
|
|
156
|
+
* @returns {import('express').Router}
|
|
157
|
+
*/
|
|
158
|
+
getRouter() {
|
|
159
|
+
return this.router;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Returns the base path associated with this router.
|
|
164
|
+
* @returns {string}
|
|
165
|
+
*/
|
|
166
|
+
getPath() {
|
|
167
|
+
return this.path;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export { Router };
|
|
171
|
+
export default Router;
|
package/core/seo.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Seo } from "./index.js";
|
|
2
|
-
export default Seo;
|
|
3
|
-
export { Seo };
|
|
1
|
+
import { Seo } from "./index.js";
|
|
2
|
+
export default Seo;
|
|
3
|
+
export { Seo };
|
package/core/seo.js
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
import Config from "./config.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Registry of SEO-enabled routes for automatic sitemap.xml and robots.txt generation.
|
|
5
|
-
* @type {Set<string>}
|
|
6
|
-
*/
|
|
7
|
-
const registeredSeoRoutes = new Set();
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Native SEO module for registering indexable routes and serving sitemap.xml and robots.txt.
|
|
11
|
-
*/
|
|
12
|
-
class Seo {
|
|
13
|
-
/**
|
|
14
|
-
* Registers a GET route path for inclusion in sitemap.xml.
|
|
15
|
-
* Ignores parameterized dynamic segments (e.g. :id) and wildcards.
|
|
16
|
-
* @param {string} basePath - Router base path.
|
|
17
|
-
* @param {string|RegExp} routePath - Route relative path.
|
|
18
|
-
* @param {string[]} [languages=[]] - Optional language prefixes.
|
|
19
|
-
*/
|
|
20
|
-
static registerRoute(basePath, routePath, languages = []) {
|
|
21
|
-
if (typeof routePath !== "string") return;
|
|
22
|
-
if (routePath.includes("*") || routePath.includes(":")) return;
|
|
23
|
-
|
|
24
|
-
const normalizedBase = basePath === "/" ? "" : basePath.replace(/\/$/, "");
|
|
25
|
-
const normalizedRoute = routePath.startsWith("/") ? routePath : `/${routePath}`;
|
|
26
|
-
const fullPath = `${normalizedBase}${normalizedRoute}` || "/";
|
|
27
|
-
|
|
28
|
-
if (languages && languages.length > 0) {
|
|
29
|
-
for (const lang of languages) {
|
|
30
|
-
const cleanLang = String(lang).trim().replace(/^\/|\/$/g, "");
|
|
31
|
-
if (cleanLang) {
|
|
32
|
-
const localizedPath = fullPath === "/" ? `/${cleanLang}` : `/${cleanLang}${fullPath}`;
|
|
33
|
-
registeredSeoRoutes.add(localizedPath);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
registeredSeoRoutes.add(fullPath);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Returns all registered SEO route paths.
|
|
43
|
-
* @returns {string[]}
|
|
44
|
-
*/
|
|
45
|
-
static getRoutes() {
|
|
46
|
-
return Array.from(registeredSeoRoutes);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Clears all registered SEO routes.
|
|
51
|
-
*/
|
|
52
|
-
static clear() {
|
|
53
|
-
registeredSeoRoutes.clear();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Generates the XML string for sitemap.xml.
|
|
58
|
-
* @param {string} [baseUrl] - Public base URL of the application.
|
|
59
|
-
* @returns {string}
|
|
60
|
-
*/
|
|
61
|
-
static generateSitemap(baseUrl) {
|
|
62
|
-
const props = Config.props();
|
|
63
|
-
const rootUrl = (baseUrl || props.appUrl || `${props.host}:${props.port}`).replace(/\/$/, "");
|
|
64
|
-
const lastmod = new Date().toISOString().split("T")[0];
|
|
65
|
-
|
|
66
|
-
const urls = Array.from(registeredSeoRoutes).map((routePath) => {
|
|
67
|
-
const priority = routePath === "/" ? "1.0" : "0.8";
|
|
68
|
-
return [
|
|
69
|
-
" <url>",
|
|
70
|
-
` <loc>${rootUrl}${routePath}</loc>`,
|
|
71
|
-
` <lastmod>${lastmod}</lastmod>`,
|
|
72
|
-
" <changefreq>weekly</changefreq>",
|
|
73
|
-
` <priority>${priority}</priority>`,
|
|
74
|
-
" </url>",
|
|
75
|
-
].join("\n");
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
return [
|
|
79
|
-
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
80
|
-
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
81
|
-
...urls,
|
|
82
|
-
"</urlset>",
|
|
83
|
-
].join("\n");
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Generates the plain text content for robots.txt.
|
|
88
|
-
* @param {string} [baseUrl] - Public base URL of the application.
|
|
89
|
-
* @returns {string}
|
|
90
|
-
*/
|
|
91
|
-
static generateRobots(baseUrl) {
|
|
92
|
-
const props = Config.props();
|
|
93
|
-
const rootUrl = (baseUrl || props.appUrl || `${props.host}:${props.port}`).replace(/\/$/, "");
|
|
94
|
-
return [
|
|
95
|
-
"User-agent: *",
|
|
96
|
-
"Allow: /",
|
|
97
|
-
"Disallow: /api/",
|
|
98
|
-
"Disallow: /debug/",
|
|
99
|
-
`Sitemap: ${rootUrl}/sitemap.xml`,
|
|
100
|
-
"",
|
|
101
|
-
].join("\n");
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export { Seo };
|
|
106
|
-
export default Seo;
|
|
1
|
+
import Config from "./config.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Registry of SEO-enabled routes for automatic sitemap.xml and robots.txt generation.
|
|
5
|
+
* @type {Set<string>}
|
|
6
|
+
*/
|
|
7
|
+
const registeredSeoRoutes = new Set();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Native SEO module for registering indexable routes and serving sitemap.xml and robots.txt.
|
|
11
|
+
*/
|
|
12
|
+
class Seo {
|
|
13
|
+
/**
|
|
14
|
+
* Registers a GET route path for inclusion in sitemap.xml.
|
|
15
|
+
* Ignores parameterized dynamic segments (e.g. :id) and wildcards.
|
|
16
|
+
* @param {string} basePath - Router base path.
|
|
17
|
+
* @param {string|RegExp} routePath - Route relative path.
|
|
18
|
+
* @param {string[]} [languages=[]] - Optional language prefixes.
|
|
19
|
+
*/
|
|
20
|
+
static registerRoute(basePath, routePath, languages = []) {
|
|
21
|
+
if (typeof routePath !== "string") return;
|
|
22
|
+
if (routePath.includes("*") || routePath.includes(":")) return;
|
|
23
|
+
|
|
24
|
+
const normalizedBase = basePath === "/" ? "" : basePath.replace(/\/$/, "");
|
|
25
|
+
const normalizedRoute = routePath.startsWith("/") ? routePath : `/${routePath}`;
|
|
26
|
+
const fullPath = `${normalizedBase}${normalizedRoute}` || "/";
|
|
27
|
+
|
|
28
|
+
if (languages && languages.length > 0) {
|
|
29
|
+
for (const lang of languages) {
|
|
30
|
+
const cleanLang = String(lang).trim().replace(/^\/|\/$/g, "");
|
|
31
|
+
if (cleanLang) {
|
|
32
|
+
const localizedPath = fullPath === "/" ? `/${cleanLang}` : `/${cleanLang}${fullPath}`;
|
|
33
|
+
registeredSeoRoutes.add(localizedPath);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
registeredSeoRoutes.add(fullPath);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Returns all registered SEO route paths.
|
|
43
|
+
* @returns {string[]}
|
|
44
|
+
*/
|
|
45
|
+
static getRoutes() {
|
|
46
|
+
return Array.from(registeredSeoRoutes);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Clears all registered SEO routes.
|
|
51
|
+
*/
|
|
52
|
+
static clear() {
|
|
53
|
+
registeredSeoRoutes.clear();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Generates the XML string for sitemap.xml.
|
|
58
|
+
* @param {string} [baseUrl] - Public base URL of the application.
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
static generateSitemap(baseUrl) {
|
|
62
|
+
const props = Config.props();
|
|
63
|
+
const rootUrl = (baseUrl || props.appUrl || `${props.host}:${props.port}`).replace(/\/$/, "");
|
|
64
|
+
const lastmod = new Date().toISOString().split("T")[0];
|
|
65
|
+
|
|
66
|
+
const urls = Array.from(registeredSeoRoutes).map((routePath) => {
|
|
67
|
+
const priority = routePath === "/" ? "1.0" : "0.8";
|
|
68
|
+
return [
|
|
69
|
+
" <url>",
|
|
70
|
+
` <loc>${rootUrl}${routePath}</loc>`,
|
|
71
|
+
` <lastmod>${lastmod}</lastmod>`,
|
|
72
|
+
" <changefreq>weekly</changefreq>",
|
|
73
|
+
` <priority>${priority}</priority>`,
|
|
74
|
+
" </url>",
|
|
75
|
+
].join("\n");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return [
|
|
79
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
80
|
+
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
81
|
+
...urls,
|
|
82
|
+
"</urlset>",
|
|
83
|
+
].join("\n");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Generates the plain text content for robots.txt.
|
|
88
|
+
* @param {string} [baseUrl] - Public base URL of the application.
|
|
89
|
+
* @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
static generateRobots(baseUrl) {
|
|
92
|
+
const props = Config.props();
|
|
93
|
+
const rootUrl = (baseUrl || props.appUrl || `${props.host}:${props.port}`).replace(/\/$/, "");
|
|
94
|
+
return [
|
|
95
|
+
"User-agent: *",
|
|
96
|
+
"Allow: /",
|
|
97
|
+
"Disallow: /api/",
|
|
98
|
+
"Disallow: /debug/",
|
|
99
|
+
`Sitemap: ${rootUrl}/sitemap.xml`,
|
|
100
|
+
"",
|
|
101
|
+
].join("\n");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { Seo };
|
|
106
|
+
export default Seo;
|
package/core/swagger.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Swagger, SwaggerOptions } from "./index.js";
|
|
2
|
-
export default Swagger;
|
|
3
|
-
export { Swagger, SwaggerOptions };
|
|
1
|
+
import { Swagger, SwaggerOptions } from "./index.js";
|
|
2
|
+
export default Swagger;
|
|
3
|
+
export { Swagger, SwaggerOptions };
|