spooder 4.5.6 → 4.5.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/README.md +5 -4
- package/package.json +1 -1
- package/src/api.ts +2 -1
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ The `CLI` component of `spooder` is a global command-line tool for running serve
|
|
|
35
35
|
`spooder` exposes a simple yet powerful API for developing servers. The API is designed to be minimal to leave control in the hands of the developer and not add overhead for features you may not need.
|
|
36
36
|
|
|
37
37
|
- [API > Serving](#api-serving)
|
|
38
|
-
- [`serve(port: number): Server`](#api-serving-serve)
|
|
38
|
+
- [`serve(port: number, hostname?: string): Server`](#api-serving-serve)
|
|
39
39
|
- [API > Routing](#api-routing)
|
|
40
40
|
- [`server.route(path: string, handler: RequestHandler, method: HTTP_METHODS)`](#api-routing-server-route)
|
|
41
41
|
- [`server.unroute(path: string)`](#api-routing-server-unroute)
|
|
@@ -468,14 +468,15 @@ In addition to the information provided by the developer, `spooder` also include
|
|
|
468
468
|
## API > Serving
|
|
469
469
|
|
|
470
470
|
<a id="api-serving-serve"></a>
|
|
471
|
-
### `serve(port: number): Server`
|
|
471
|
+
### `serve(port: number, hostname?: string): Server`
|
|
472
472
|
|
|
473
|
-
Bootstrap a server on the specified port.
|
|
473
|
+
Bootstrap a server on the specified port (and optional hostname).
|
|
474
474
|
|
|
475
475
|
```ts
|
|
476
476
|
import { serve } from 'spooder';
|
|
477
477
|
|
|
478
|
-
const server = serve(8080);
|
|
478
|
+
const server = serve(8080); // port only
|
|
479
|
+
const server = serve(3000, '0.0.0.0'); // optional hostname
|
|
479
480
|
```
|
|
480
481
|
|
|
481
482
|
By default, the server responds with:
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -616,7 +616,7 @@ function is_valid_method(method: HTTP_METHODS, req: Request): boolean {
|
|
|
616
616
|
return req.method === method;
|
|
617
617
|
}
|
|
618
618
|
|
|
619
|
-
export function serve(port: number) {
|
|
619
|
+
export function serve(port: number, hostname?: string) {
|
|
620
620
|
const routes = new Array<[string[], RequestHandler, HTTP_METHODS]>();
|
|
621
621
|
const handlers = new Map<number, StatusCodeHandler>();
|
|
622
622
|
|
|
@@ -744,6 +744,7 @@ export function serve(port: number) {
|
|
|
744
744
|
|
|
745
745
|
const server = Bun.serve({
|
|
746
746
|
port,
|
|
747
|
+
hostname,
|
|
747
748
|
development: false,
|
|
748
749
|
|
|
749
750
|
async fetch(req: Request): Promise<Response> {
|