@ttoss/http-server 0.3.2 → 0.4.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/README.md CHANGED
@@ -11,7 +11,7 @@ pnpm add @ttoss/http-server
11
11
  ## Quick Start
12
12
 
13
13
  ```typescript
14
- import { App, Router, bodyParser, cors } from '@ttoss/http-server';
14
+ import { App, Router, bodyParser, cors, serve } from '@ttoss/http-server';
15
15
 
16
16
  const app = new App();
17
17
 
@@ -50,6 +50,57 @@ app.listen(3000);
50
50
 
51
51
  ## Core Features
52
52
 
53
+ ### Static File Serving
54
+
55
+ Serve static files from a directory using the `serve` middleware:
56
+
57
+ ```typescript
58
+ import { App, serve } from '@ttoss/http-server';
59
+
60
+ const app = new App();
61
+
62
+ // Serve files from the 'public' directory
63
+ app.use(serve('./public'));
64
+
65
+ app.listen(3000);
66
+ // Files in ./public are now accessible at http://localhost:3000
67
+ ```
68
+
69
+ **Advanced Options:**
70
+
71
+ ```typescript
72
+ // With custom options
73
+ app.use(
74
+ serve('./public', {
75
+ maxage: 3600000, // Cache files for 1 hour (in milliseconds)
76
+ index: 'index.html', // Default file to serve for directories
77
+ hidden: false, // Don't serve hidden files
78
+ gzip: true, // Enable gzip compression
79
+ })
80
+ );
81
+ ```
82
+
83
+ **Combining with Routes:**
84
+
85
+ ```typescript
86
+ import { App, Router, serve } from '@ttoss/http-server';
87
+
88
+ const app = new App();
89
+ const router = new Router();
90
+
91
+ // Define API routes first
92
+ router.get('/api/users', (ctx) => {
93
+ ctx.body = [{ id: 1, name: 'John' }];
94
+ });
95
+
96
+ app.use(router.routes());
97
+
98
+ // Static files are served after API routes
99
+ app.use(serve('./public'));
100
+
101
+ app.listen(3000);
102
+ ```
103
+
53
104
  ### Route Parameters
54
105
 
55
106
  ```typescript
@@ -109,5 +160,6 @@ All exports are re-exported from established Koa ecosystem packages:
109
160
  - **`bodyParser`** - [Koa body parser](https://github.com/koajs/bodyparser) for JSON/form parsing
110
161
  - **`cors`** - [Koa CORS](https://github.com/koajs/cors) for cross-origin requests
111
162
  - **`multer`** - [Koa multer](https://github.com/koajs/multer) for file uploads
163
+ - **`serve`** - [Koa static](https://github.com/koajs/static) for serving static files
112
164
  - **`addHealthCheck({ app, path? })`** - Adds a health endpoint (defaults to `/health`) returning `{ status: 'ok' }`
113
165
  - **`MulterFile`** (type) - File type for uploaded files
package/dist/esm/index.js CHANGED
@@ -11,6 +11,7 @@ import cors from "@koa/cors";
11
11
  import multer from "@koa/multer";
12
12
  import Router2 from "@koa/router";
13
13
  import App from "koa";
14
+ import serve from "koa-static";
14
15
 
15
16
  // src/addHealthCheck.ts
16
17
  import Router from "@koa/router";
@@ -30,4 +31,4 @@ var addHealthCheck = /* @__PURE__ */__name(({
30
31
 
31
32
  // src/index.ts
32
33
  export * from "@koa/router";
33
- export { App, Router2 as Router, addHealthCheck, bodyParser, cors, multer };
34
+ export { App, Router2 as Router, addHealthCheck, bodyParser, cors, multer, serve };
package/dist/index.d.cts CHANGED
@@ -5,6 +5,7 @@ export * from '@koa/router';
5
5
  export { default as Router } from '@koa/router';
6
6
  import App from 'koa';
7
7
  export { default as App } from 'koa';
8
+ export { default as serve } from 'koa-static';
8
9
 
9
10
  interface AddHealthCheckOptions {
10
11
  /**
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export * from '@koa/router';
5
5
  export { default as Router } from '@koa/router';
6
6
  import App from 'koa';
7
7
  export { default as App } from 'koa';
8
+ export { default as serve } from 'koa-static';
8
9
 
9
10
  interface AddHealthCheckOptions {
10
11
  /**
package/dist/index.js CHANGED
@@ -48,7 +48,8 @@ __export(index_exports, {
48
48
  addHealthCheck: () => addHealthCheck,
49
49
  bodyParser: () => import_bodyparser.bodyParser,
50
50
  cors: () => import_cors.default,
51
- multer: () => import_multer.default
51
+ multer: () => import_multer.default,
52
+ serve: () => import_koa_static.default
52
53
  });
53
54
  module.exports = __toCommonJS(index_exports);
54
55
  var import_bodyparser = require("@koa/bodyparser");
@@ -56,6 +57,7 @@ var import_cors = __toESM(require("@koa/cors"), 1);
56
57
  var import_multer = __toESM(require("@koa/multer"), 1);
57
58
  var import_router2 = __toESM(require("@koa/router"), 1);
58
59
  var import_koa = __toESM(require("koa"), 1);
60
+ var import_koa_static = __toESM(require("koa-static"), 1);
59
61
 
60
62
  // src/addHealthCheck.ts
61
63
  var import_router = __toESM(require("@koa/router"), 1);
@@ -83,5 +85,6 @@ __reExport(index_exports, require("@koa/router"), module.exports);
83
85
  bodyParser,
84
86
  cors,
85
87
  multer,
88
+ serve,
86
89
  ...require("@koa/router")
87
90
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/http-server",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "HTTP Server for ttoss environment",
5
5
  "license": "MIT",
6
6
  "author": "ttoss",
@@ -30,6 +30,7 @@
30
30
  "@koa/multer": "^4.0.0",
31
31
  "@koa/router": "^15.1.1",
32
32
  "koa": "^3.1.1",
33
+ "koa-static": "^5.0.0",
33
34
  "multer": "2.0.2"
34
35
  },
35
36
  "devDependencies": {
@@ -37,6 +38,7 @@
37
38
  "@types/koa__cors": "^5.0.1",
38
39
  "@types/koa__multer": "^2.0.8",
39
40
  "@types/koa__router": "^12.0.5",
41
+ "@types/koa-static": "^4.0.4",
40
42
  "jest": "^30.2.0",
41
43
  "supertest": "^7.1.4",
42
44
  "tsup": "^8.5.1",