@server/next 0.15.0 → 0.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "An experimental reimplementation of server.js focused on the DX",
5
5
  "homepage": "https://node-server.com/",
6
6
  "repository": "https://github.com/franciscop/server-next.git",
package/readme.md CHANGED
@@ -7,7 +7,7 @@
7
7
  A fully-fledged web server for Node.js, with all the basics covered for you:
8
8
 
9
9
  ```js
10
- import server, { get, post, put, use, error } from 'server';
10
+ import server, { get, post, put, use } from 'server';
11
11
 
12
12
  // Create a running instance of the server
13
13
  const app = server(config, [pluginA, pluginB]);
@@ -17,8 +17,7 @@ app([
17
17
  get('/users', getUsers),
18
18
  post('/users', createUser),
19
19
  put('/users/:id', editUser),
20
- use('/admin/*', dashboard),
21
- error(ctx => console.log(ctx.error))
20
+ use('/admin/*', dashboard)
22
21
  ]);
23
22
  ```
24
23
 
@@ -41,7 +40,9 @@ Why? The ecosystem is moving out of server-rendered websites so we are as well.
41
40
 
42
41
  ## Progress
43
42
 
44
- - Router has `get` and `post`, as well as URL pattern matches
43
+ - Router has all verbs, as well as URL pattern matches
44
+ - Full URL parsing, including `query` and `params` in ctx.url.
45
+ - Body and Files parsing is working (TODO: try with binary files and add tests)
45
46
  - The middleware can return:
46
47
  - A number and it'll be set as the status code
47
48
  - A string and it'll be sent as plain text or html (if it starts with "<")
package/src/index.js CHANGED
@@ -278,3 +278,12 @@ export const head = (pattern, callback) => {
278
278
  return callback(ctx);
279
279
  };
280
280
  };
281
+
282
+ export const use = (pattern, callback) => {
283
+ return (ctx) => {
284
+ const match = pathPattern(pattern, ctx.url.path);
285
+ if (!match) return null;
286
+ ctx.url.params = match;
287
+ return callback(ctx);
288
+ };
289
+ };