forked from topcoder-archive/tc-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
154 lines (131 loc) · 6.86 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved.
*
* @version 1.11
* @author vangavroche, Sky_, TCSASSEMBLER, muzehyun, Ghost_141
* Changes in 1.1:
* - add routes for search challenges
* Changes in 1.2:
* - add route for top
* Changes in 1.3:
* - add routes for all stub methods
* - add routes for cache test
* Changes in 1.4:
* - reorder route for studio contest details
* Changes in 1.5:
* - add routes for software rating history and distribution
* - reorder route for studio challenge details
* Changes in 1.6:
* - add route oauth test
* Changes in 1.7:
* - add route oauth
* Changes in 1.8:
* - add route for bugs
* Changes in 1.9:
* - add route for client challenge costs
* Changes in 1.10:
* - added routes for terms api
* Changes in 1.11:
* - add invoice history api.
*/
/* ---------------------
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/1
],
post: [
{ path: "/login/:userID(^\\d{3}$)", action: "login" } // (POST) /api/login/123
],
all: [
{ path: "/user/:userID", action: "user" } // (*) / /api/user/123
]
}
---------------------- */
/**
* Methods that are used only in test cases.
*/
var testMethods = {
get: [
{path: "/test/cache/oauth", action: "cacheTestOAuth"},
{path: "/test/cache/error", action: "cacheTestError"},
{path: "/test/cache/hits", action: "cacheTestGetHits"},
{path: "/test/cache/reset", action: "cacheTestResetHits"},
{path: "/test/cache/disabled", action: "cacheDisabled"},
{path: "/test/cache", action: "cacheTest"},
{path: "/test/oauth", action: "oauthTest"}
]
};
////////////
// ROUTES //
////////////
exports.routes = {
get: [
{ path: "/:apiVersion/logs", action: "getLogTail" },
{ path: "/:apiVersion/challenges", action: "searchSoftwareAndStudioChallenges" },
{ path: "/:apiVersion/develop/challengetypes", action: "softwareTypes" },
{ path: "/:apiVersion/develop/challenges/:contestId", action: "getSoftwareChallenge" },
{ path: "/:apiVersion/develop/statistics/tops/:contestType", action: "getTops" },
{ path: "/:apiVersion/develop/statistics/:handle/:challengeType", action: "getSoftwareRatingHistoryAndDistribution" },
{ path: "/:apiVersion/develop/challenges", action: "searchSoftwareChallenges" },
{ path: "/:apiVersion/develop/reviewOpportunities", action: "searchReviewOpportunities" },
{ path: "/:apiVersion/design/challengetypes", action: "studioTypes" },
{ path: "/:apiVersion/design/reviewOpportunities/:id", action: "getStudioReviewOpportunity" },
{ path: "/:apiVersion/design/challenges/:contestId", action: "getStudioChallenge" },
{ path: "/:apiVersion/design/challenges", action: "searchStudioChallenges" },
{ path: "/:apiVersion/design/reviewOpportunities", action: "getStudioReviewOpportunities" },
{ path: "/:apiVersion/users/:handle/statistics/develop", action: "getSoftwareStatistics" },
{ path: "/:apiVersion/users/:handle/statistics/design", action: "getStudioStatistics" },
{ path: "/:apiVersion/users/:handle/statistics/data/marathon", action: "getMarathonStatistics" },
{ path: "/:apiVersion/users/:handle/statistics/data/srm", action: "getAlgorithmStatistics" },
{ path: "/:apiVersion/users/:handle", action: "getBasicUserProfile" },
{ path: "/:apiVersion/data/srm/challenges/:id", action: "getSRMChallenge" },
{ path: "/:apiVersion/data/srm/challenges", action: "searchSRMChallenges" },
{ path: "/:apiVersion/data/marathon/challenges/:id", action: "getMarathonChallenge" },
{ path: "/:apiVersion/data/marathon/challenges", action: "searchMarathonChallenges" },
{ path: "/:apiVersion/data/marathon/statistics/tops", action: "getMarathonTops" },
{ path: "/:apiVersion/data/srm/statistics/tops", action: "getSRMTops" },
{ path: "/:apiVersion/data/countries", action: "countries" },
{ path: "/:apiVersion/terms/:challengeId(\\d+)", action: "getChallengeTerms"},
{ path: "/:apiVersion/terms/detail/:termsOfUseId", action: "getTermsOfUse"},
//example secure route using oauth. for future reference.
{ path: "/:apiVersion/secure/challengetypes", action: "softwareTypesSecured" },
{ path: "/:apiVersion/platform/statistics", action: "tcDirectFacts" },
{ path: "/:apiVersion/download/document/:docId", action: "downloadDocument" },
{ path: "/:apiVersion/reports/client/costs", action: "getClientChallengeCosts" },
{ path: "/:apiVersion/reports/costs/:startDate/:endDate", action: "getChallengeCosts" },
{ path: "/:apiVersion/bugs/:jiraProjectId/:status", action: "bugs" },
{ path: "/:apiVersion/bugs/:jiraProjectId", action: "bugs" },
{ path: "/:apiVersion/bugs", action: "bugs" },
//Stubs APIs
{ path: "/:apiVersion/software/reviewOpportunities/:id", action: "getReviewOpportunity" },
{ path: "/:apiVersion/data/reviewOpportunities/:id", action: "getAlgorithmsReviewOpportunity" },
{ path: "/:apiVersion/data/reviewOpportunities", action: "getAlgorithmsReviewOpportunities" },
{ path: "/:apiVersion/software/reviewers/:contestType", action: "getChallengeReviewers" },
{ path: "/:apiVersion/design/statistics/tops/:challengeType", action: "getStudioTops" },
{ path: "/:apiVersion/data/challengetypes", action: "algorithmsChallengeTypes" }
].concat(testMethods.get),
post: [
{ path: "/:apiVersion/users", action: "memberRegister" },
{ path: "/:apiVersion/auth", action: "generateJwt" }
]
};