-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
49 lines (40 loc) · 1.81 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
44
45
46
47
48
49
/* ---------------------
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.
- routes remain optional
- actions defiend 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 = {
get: [
{ path: "/status", action: "status" }, // (GET) /api/users
{ path: "/politician", action: "politician" } // (GET) /api/users
]
};