forked from actionhero/actionhero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
43 lines (34 loc) · 1.64 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* ---------------------
routes.js
For web clients (http and https) you can define an optional RESTful mapping to help route requests to actions.
If the client doesn't specify and action in a param, and the base route isn't a named action, the action will attempt to be discerned from this routes.js file.
- actions defined in params directly 'action=theAction' or hitting the named URL for an action '/api/theAction' will always override RESTful routing
- you can mix explicitly defined params with route-defined params. If there is an overlap, the route-defined params win
- IE: /api/user/123?userId=456 => 'connection.userId = 123'
- this is a change from previous versions
- routes defined with the 'all' method will be duplicated to 'get', 'put', 'post', and 'delete'
- use ':variable' to defined 'variable'
- undefined ':variable' will match
- IE: '/api/user/' WILL match '/api/user/:userId'
- routes are matched as defined here top-down
- you can optionally define a regex match along with your route variable
- IE: { path:'/game/:id(^[a-z]{0,10}$)', action: 'gamehandler' }
- be sure to double-escape when needed: { path: '/login/:userID(^\\d{3}$)', action: 'login' }
example:
{
get: [
{ path: '/users', action: 'usersList' }, // (GET) /api/users
{ path: '/search/:term/limit/:limit/offset/:offset', action: 'search' }, // (GET) /api/search/car/limit/10/offset/100
],
post: [
{ path: '/login/:userID(^\\d{3}$)', action: 'login' } // (POST) /api/login/123
],
all: [
{ path: '/user/:userID', action: 'user' } // (*) / /api/user/123
]
}
---------------------- */
////////////
// ROUTES //
////////////
exports.routes = {};