sleepy-serv 0.1.2 → 0.2.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 +8 -3
- package/package.json +1 -1
- package/src/index.js +5 -2
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ Here's an example of a simple handler function:
|
|
|
74
74
|
|
|
75
75
|
```js
|
|
76
76
|
export default function (req) {
|
|
77
|
-
return Response('Hello world')
|
|
77
|
+
return new Response('Hello world')
|
|
78
78
|
}
|
|
79
79
|
```
|
|
80
80
|
|
|
@@ -131,7 +131,7 @@ export default async function (req) {
|
|
|
131
131
|
const users = await sql`
|
|
132
132
|
SELECT * FROM Users
|
|
133
133
|
WHERE userId=${req.params.userId}
|
|
134
|
-
|
|
134
|
+
`
|
|
135
135
|
|
|
136
136
|
const foundUser = users[0]
|
|
137
137
|
|
|
@@ -192,7 +192,7 @@ For example:
|
|
|
192
192
|
put.js
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
-
The middleware defined in `/api/meta.js` will be applied the following routes:
|
|
195
|
+
The middleware defined in `/api/meta.js` will be applied by the following routes:
|
|
196
196
|
|
|
197
197
|
- `GET /`
|
|
198
198
|
- `GET /users`
|
|
@@ -269,3 +269,8 @@ const app = await createApp(PORT, import.meta.dirname, {
|
|
|
269
269
|
- `$ cd ../example`
|
|
270
270
|
- `$ npm link sleepy-serv`
|
|
271
271
|
1. Finally, run the app: `$ bun --watch run start`
|
|
272
|
+
|
|
273
|
+
## Running Tests
|
|
274
|
+
|
|
275
|
+
- Use `bun`'s built-in test runner
|
|
276
|
+
- Run tests from the `./lib` directory
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -255,9 +255,12 @@ async function buildRoutes (rootPath, opts) {
|
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
-
function buildServer (port, routes) {
|
|
258
|
+
function buildServer (port, routes, opts) {
|
|
259
|
+
const hostname = opts.hostname || '0.0.0.0'
|
|
260
|
+
|
|
259
261
|
return Bun.serve({
|
|
260
262
|
port,
|
|
263
|
+
hostname,
|
|
261
264
|
routes: routes.server,
|
|
262
265
|
fetch (_req) {
|
|
263
266
|
throw new NotFoundError()
|
|
@@ -290,7 +293,7 @@ function processIO (port, server, opts) {
|
|
|
290
293
|
|
|
291
294
|
export async function createApp (port, rootPath, opts = {}) {
|
|
292
295
|
const routes = await buildRoutes(rootPath, opts)
|
|
293
|
-
const server = buildServer(port, routes)
|
|
296
|
+
const server = buildServer(port, routes, opts)
|
|
294
297
|
|
|
295
298
|
processIO(port, server, opts)
|
|
296
299
|
|