@ttoss/http-server 0.3.0 → 0.3.1
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/dist/index.d.cts +41 -0
- package/dist/index.js +82 -0
- package/package.json +2 -1
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export { bodyParser } from '@koa/bodyparser';
|
|
2
|
+
export { default as cors } from '@koa/cors';
|
|
3
|
+
export { File as MulterFile, default as multer } from '@koa/multer';
|
|
4
|
+
export { default as Router } from '@koa/router';
|
|
5
|
+
import App from 'koa';
|
|
6
|
+
export { default as App } from 'koa';
|
|
7
|
+
|
|
8
|
+
interface AddHealthCheckOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The Koa application instance to attach the health check to.
|
|
11
|
+
*/
|
|
12
|
+
app: App;
|
|
13
|
+
/**
|
|
14
|
+
* The path for the health endpoint.
|
|
15
|
+
* @default '/health'
|
|
16
|
+
*/
|
|
17
|
+
path?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Adds a health check endpoint to the Koa application.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { App, addHealthCheck } from '@ttoss/http-server';
|
|
25
|
+
*
|
|
26
|
+
* const app = new App();
|
|
27
|
+
* addHealthCheck({ app });
|
|
28
|
+
*
|
|
29
|
+
* app.listen(3000);
|
|
30
|
+
* // GET /health returns { status: 'ok' }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Custom path
|
|
36
|
+
* addHealthCheck({ app, path: '/health' });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare const addHealthCheck: ({ app, path, }: AddHealthCheckOptions) => void;
|
|
40
|
+
|
|
41
|
+
export { type AddHealthCheckOptions, addHealthCheck };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
11
|
+
value,
|
|
12
|
+
configurable: true
|
|
13
|
+
});
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all) __defProp(target, name, {
|
|
16
|
+
get: all[name],
|
|
17
|
+
enumerable: true
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
23
|
+
get: () => from[key],
|
|
24
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
35
|
+
value: mod,
|
|
36
|
+
enumerable: true
|
|
37
|
+
}) : target, mod));
|
|
38
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
39
|
+
value: true
|
|
40
|
+
}), mod);
|
|
41
|
+
|
|
42
|
+
// src/index.ts
|
|
43
|
+
var index_exports = {};
|
|
44
|
+
__export(index_exports, {
|
|
45
|
+
App: () => import_koa.default,
|
|
46
|
+
Router: () => import_router2.default,
|
|
47
|
+
addHealthCheck: () => addHealthCheck,
|
|
48
|
+
bodyParser: () => import_bodyparser.bodyParser,
|
|
49
|
+
cors: () => import_cors.default,
|
|
50
|
+
multer: () => import_multer.default
|
|
51
|
+
});
|
|
52
|
+
module.exports = __toCommonJS(index_exports);
|
|
53
|
+
var import_bodyparser = require("@koa/bodyparser");
|
|
54
|
+
var import_cors = __toESM(require("@koa/cors"), 1);
|
|
55
|
+
var import_multer = __toESM(require("@koa/multer"), 1);
|
|
56
|
+
var import_router2 = __toESM(require("@koa/router"), 1);
|
|
57
|
+
var import_koa = __toESM(require("koa"), 1);
|
|
58
|
+
|
|
59
|
+
// src/addHealthCheck.ts
|
|
60
|
+
var import_router = __toESM(require("@koa/router"), 1);
|
|
61
|
+
var addHealthCheck = /* @__PURE__ */__name(({
|
|
62
|
+
app,
|
|
63
|
+
path = "/health"
|
|
64
|
+
}) => {
|
|
65
|
+
const router = new import_router.default();
|
|
66
|
+
router.get(path, ctx => {
|
|
67
|
+
ctx.body = {
|
|
68
|
+
status: "ok"
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
app.use(router.routes());
|
|
72
|
+
app.use(router.allowedMethods());
|
|
73
|
+
}, "addHealthCheck");
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
App,
|
|
77
|
+
Router,
|
|
78
|
+
addHealthCheck,
|
|
79
|
+
bodyParser,
|
|
80
|
+
cors,
|
|
81
|
+
multer
|
|
82
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/http-server",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "HTTP Server for ttoss environment",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
18
|
"import": "./dist/esm/index.js",
|
|
19
|
+
"require": "./dist/index.js",
|
|
19
20
|
"types": "./dist/index.d.ts"
|
|
20
21
|
}
|
|
21
22
|
},
|