@darthcav/ts-http-server 0.4.0 → 0.5.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 +24 -16
- package/dist/launcher.js +2 -2
- package/dist/launcher.js.map +1 -1
- package/dist/start.js +6 -2
- package/dist/start.js.map +1 -1
- package/package.json +4 -4
- package/src/launcher.ts +2 -2
- package/src/start.ts +6 -2
package/README.md
CHANGED
|
@@ -59,11 +59,11 @@ main(pkg.name, logger, false, () => {
|
|
|
59
59
|
})
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
The `defaultPlugins` function accepts an optional `baseDir` to resolve the `src/` folder
|
|
63
|
-
|
|
62
|
+
The `defaultPlugins` function accepts an optional `baseDir` to resolve the `src/` folder (defaults to the parent of
|
|
63
|
+
`import.meta.dirname`):
|
|
64
64
|
|
|
65
65
|
```ts
|
|
66
|
-
const plugins = defaultPlugins({ locals, baseDir: import.meta.dirname })
|
|
66
|
+
const plugins = defaultPlugins({ locals, baseDir: import.meta.dirname });
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
## Getting Started
|
|
@@ -94,7 +94,7 @@ npm run doc
|
|
|
94
94
|
|
|
95
95
|
## Project Structure
|
|
96
96
|
|
|
97
|
-
```
|
|
97
|
+
```text
|
|
98
98
|
src/
|
|
99
99
|
index.ts # Library entry point
|
|
100
100
|
start.ts # Application entry point
|
|
@@ -117,12 +117,12 @@ docker build -t ts-http-server .
|
|
|
117
117
|
|
|
118
118
|
Available build arguments:
|
|
119
119
|
|
|
120
|
-
| Argument
|
|
121
|
-
|
|
122
|
-
| `BUILD_IMAGE`
|
|
123
|
-
| `APP_USER`
|
|
124
|
-
| `APP_GROUP`
|
|
125
|
-
| `CONTAINER_EXPOSE_PORT
|
|
120
|
+
| Argument | Default | Description |
|
|
121
|
+
| ----------------------- | ---------------- | --------------------------------------------- |
|
|
122
|
+
| `BUILD_IMAGE` | `node:25-alpine` | Base image for both stages |
|
|
123
|
+
| `APP_USER` | `node` | OS user owning `/app` and running the process |
|
|
124
|
+
| `APP_GROUP` | `node` | OS group owning `/app` |
|
|
125
|
+
| `CONTAINER_EXPOSE_PORT` | `8888` | Port exposed by the container |
|
|
126
126
|
|
|
127
127
|
```shell
|
|
128
128
|
docker build \
|
|
@@ -132,10 +132,17 @@ docker build \
|
|
|
132
132
|
-t ts-http-server .
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
+
Runtime environment variables:
|
|
136
|
+
|
|
137
|
+
| Variable | Default | Description |
|
|
138
|
+
| ----------------------- | ----------- | ------------------------------------------ |
|
|
139
|
+
| `HOST` | `localhost` | Bind address (use `0.0.0.0` in containers) |
|
|
140
|
+
| `CONTAINER_EXPOSE_PORT` | `8888` | Port the server listens on |
|
|
141
|
+
|
|
135
142
|
### Run
|
|
136
143
|
|
|
137
144
|
```shell
|
|
138
|
-
docker run --rm -p 8888:8888 ts-http-server
|
|
145
|
+
docker run --rm -p 8888:8888 -e HOST=0.0.0.0 ts-http-server
|
|
139
146
|
```
|
|
140
147
|
|
|
141
148
|
### Docker Compose
|
|
@@ -148,13 +155,14 @@ services:
|
|
|
148
155
|
- "8888:8888"
|
|
149
156
|
environment:
|
|
150
157
|
NODE_ENV: production
|
|
151
|
-
|
|
158
|
+
HOST: 0.0.0.0
|
|
159
|
+
# Override the running user at runtime
|
|
160
|
+
# (must match a valid UID:GID on the host if needed)
|
|
152
161
|
user: "1001:1001"
|
|
153
162
|
```
|
|
154
163
|
|
|
155
|
-
> **Note:** `APP_USER`/`APP_GROUP` are baked in at build time via `chown` and `USER`.
|
|
156
|
-
>
|
|
157
|
-
> **not** the `environment:` block.
|
|
164
|
+
> **Note:** `APP_USER`/`APP_GROUP` are baked in at build time via `chown` and `USER`. To override the running user at
|
|
165
|
+
> runtime use the `user:` key in docker-compose, **not** the `environment:` block.
|
|
158
166
|
|
|
159
167
|
## License
|
|
160
168
|
|
|
@@ -162,7 +170,7 @@ services:
|
|
|
162
170
|
|
|
163
171
|
[node-version]: https://img.shields.io/badge/node-%3E%3D25-orange.svg?style=flat-square
|
|
164
172
|
[node-url]: https://nodejs.org
|
|
165
|
-
[version-image]: https://img.shields.io/badge/version-0.
|
|
173
|
+
[version-image]: https://img.shields.io/badge/version-0.5.0-blue.svg?style=flat-square
|
|
166
174
|
[ci-badge]: https://github.com/darthcav/ts-http-server/actions/workflows/tests.yml/badge.svg
|
|
167
175
|
[coverage-badge]: https://codecov.io/github/darthcav/ts-http-server/branch/dev/graph/badge.svg?token=K8Q4T4N9SG
|
|
168
176
|
[coverage-url]: https://codecov.io/github/darthcav/ts-http-server
|
package/dist/launcher.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import process
|
|
1
|
+
import process from "node:process";
|
|
2
2
|
import { notFound } from "@hapi/boom";
|
|
3
3
|
import Fastify, {} from "fastify";
|
|
4
4
|
import defaultErrorHandler from "./defaults/defaultErrorHandler.js";
|
|
@@ -19,7 +19,7 @@ import { onResponse, preHandler } from "./index.js";
|
|
|
19
19
|
*/
|
|
20
20
|
export default function launcher({ logger, locals, plugins, routes, decorators, opts, done, }) {
|
|
21
21
|
const host = locals?.host ?? "localhost";
|
|
22
|
-
const port = locals?.port ??
|
|
22
|
+
const port = locals?.port ?? 8888;
|
|
23
23
|
const fastify = Fastify({
|
|
24
24
|
...defaultFastifyOptions(logger),
|
|
25
25
|
...opts,
|
package/dist/launcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"launcher.js","sourceRoot":"","sources":["../src/launcher.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,
|
|
1
|
+
{"version":3,"file":"launcher.js","sourceRoot":"","sources":["../src/launcher.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,OAAO,EAAE,EAAwB,MAAM,SAAS,CAAA;AACvD,OAAO,mBAAmB,MAA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AmB,CAAC,CAAA;IAE5C,sCAAsC;IACtC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;IACzC,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;IAEzC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE;QACrC,IAAI,KAAK,EAAE,CAAC;YACR,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YAChC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;QACD,IAAI,EAAE,EAAE,CAAA;IACZ,CAAC,CAAC,CAAA;IAEF,OAAO,OAAO,CAAA;AAClB,CAAC"}
|
package/dist/start.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import process from "node:process";
|
|
1
|
+
import process, { env } from "node:process";
|
|
2
2
|
import { getConsoleLogger, main } from "@darthcav/ts-utils";
|
|
3
3
|
import pkg from "../package.json" with { type: "json" };
|
|
4
4
|
import { defaultPlugins, defaultRoutes, launcher } from "./index.js";
|
|
5
5
|
const logger = await getConsoleLogger(pkg.name, "info");
|
|
6
6
|
main(pkg.name, logger, () => {
|
|
7
|
-
const locals = {
|
|
7
|
+
const locals = {
|
|
8
|
+
pkg,
|
|
9
|
+
host: env["HOST"] ?? "localhost",
|
|
10
|
+
port: Number(env["CONTAINER_EXPOSE_PORT"]) ?? 8888,
|
|
11
|
+
};
|
|
8
12
|
const plugins = defaultPlugins({ locals });
|
|
9
13
|
const routes = defaultRoutes();
|
|
10
14
|
const fastify = launcher({ logger, locals, plugins, routes });
|
package/dist/start.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.js","sourceRoot":"","sources":["../src/start.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"start.js","s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MAAM,CAAC,KAAK,CAAC,0BAA0B,KAAK,EAAE,CAAC,CAAA;YAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC,CAAC,CACT,CAAA;IACL,CAAC;AACL,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darthcav/ts-http-server",
|
|
3
3
|
"description": "A TypeScript HTTP server for Node.js >= 25",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "darthcav",
|
|
7
7
|
"url": "https://github.com/darthcav"
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"src",
|
|
22
|
-
"!src/**/*.test.ts",
|
|
23
22
|
"!src/__tests__",
|
|
24
23
|
"dist"
|
|
25
24
|
],
|
|
@@ -43,6 +42,7 @@
|
|
|
43
42
|
"@types/ejs": "3.1.5",
|
|
44
43
|
"@types/node": "25.5.0",
|
|
45
44
|
"asserttt": "1.0.1",
|
|
45
|
+
"prettier": "3.8.1",
|
|
46
46
|
"shx": "0.4.0",
|
|
47
47
|
"typedoc": "0.28.18"
|
|
48
48
|
},
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"test:coverage": "node --env-file=.env.local --experimental-test-coverage --test 'src/**/*.test.ts'",
|
|
68
68
|
"test:coverage:lcov": "shx mkdir -p coverage && node --env-file=.env.local --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test-reporter=spec --test-reporter-destination=stdout --test 'src/**/*.test.ts'",
|
|
69
69
|
"\n===== Linter =====": "",
|
|
70
|
-
"lint": "biome check .",
|
|
71
|
-
"lint:fix": "biome check --write .",
|
|
70
|
+
"lint": "biome check . && prettier --check \"**/*.md\" --ignore-path .gitignore",
|
|
71
|
+
"lint:fix": "biome check --write . && prettier --write \"**/*.md\" --ignore-path .gitignore",
|
|
72
72
|
"\n===== TypeDoc =====": "",
|
|
73
73
|
"doc": "shx rm -rf public/* && typedoc --tsconfig tsconfig.json"
|
|
74
74
|
}
|
package/src/launcher.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import process
|
|
1
|
+
import process from "node:process"
|
|
2
2
|
import { notFound } from "@hapi/boom"
|
|
3
3
|
import Fastify, { type FastifyInstance } from "fastify"
|
|
4
4
|
import defaultErrorHandler from "./defaults/defaultErrorHandler.ts"
|
|
@@ -29,7 +29,7 @@ export default function launcher({
|
|
|
29
29
|
done,
|
|
30
30
|
}: LauncherOptions): FastifyInstance {
|
|
31
31
|
const host = locals?.host ?? "localhost"
|
|
32
|
-
const port = locals?.port ??
|
|
32
|
+
const port = locals?.port ?? 8888
|
|
33
33
|
|
|
34
34
|
const fastify = Fastify({
|
|
35
35
|
...defaultFastifyOptions(logger),
|
package/src/start.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import process from "node:process"
|
|
1
|
+
import process, { env } from "node:process"
|
|
2
2
|
import { getConsoleLogger, main } from "@darthcav/ts-utils"
|
|
3
3
|
import pkg from "../package.json" with { type: "json" }
|
|
4
4
|
import { defaultPlugins, defaultRoutes, launcher } from "./index.ts"
|
|
@@ -6,7 +6,11 @@ import { defaultPlugins, defaultRoutes, launcher } from "./index.ts"
|
|
|
6
6
|
const logger = await getConsoleLogger(pkg.name, "info")
|
|
7
7
|
|
|
8
8
|
main(pkg.name, logger, () => {
|
|
9
|
-
const locals = {
|
|
9
|
+
const locals = {
|
|
10
|
+
pkg,
|
|
11
|
+
host: env["HOST"] ?? "localhost",
|
|
12
|
+
port: Number(env["CONTAINER_EXPOSE_PORT"]) ?? 8888,
|
|
13
|
+
}
|
|
10
14
|
const plugins = defaultPlugins({ locals })
|
|
11
15
|
const routes = defaultRoutes()
|
|
12
16
|
|