Skip to content

Commit

Permalink
Add an "all" methods choice (#1147)
Browse files Browse the repository at this point in the history
Fallback mode already allows for global route with rules, but the possibility to use this global route on all methods is missing.
Closes #221
  • Loading branch information
255kb committed Sep 25, 2023
1 parent 398f224 commit 8bdd8bb
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 115 deletions.
106 changes: 0 additions & 106 deletions packages/commons-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -273,6 +273,7 @@ export const RouteSchema = Joi.object<Route, true>({
method: Joi.string()
.allow('')
.valid(
Methods.all,
Methods.get,
Methods.post,
Methods.put,
Expand Down
1 change: 1 addition & 0 deletions packages/commons/src/models/route.model.ts
Expand Up @@ -87,6 +87,7 @@ export type Route = {
export type Header = { key: string; value: string };

export enum Methods {
all = 'all',
get = 'get',
post = 'post',
put = 'put',
Expand Down
Expand Up @@ -89,6 +89,11 @@ export class EnvironmentRoutesComponent implements OnInit, OnDestroy {
public scrollToBottom = this.uiService.scrollToBottom;
public databuckets$: Observable<DropdownItems>;
public methods: DropdownItems = [
{
value: Methods.all,
label: 'All methods',
classes: 'route-badge-all-text'
},
{
label: 'HTTP',
category: true
Expand Down
17 changes: 9 additions & 8 deletions packages/desktop/src/renderer/styles/styles.scss
Expand Up @@ -122,10 +122,11 @@ input,
}

// route badges (methods)
$route-badges: ('crud', lighten($cyan, 15%)), ('get', lighten($blue, 10%)),
('put', lighten($orange, 10%)), ('post', lighten($green, 10%)),
('delete', lighten($red, 17%)), ('head', lighten($purple, 25%)),
('patch', $teal), ('options', lighten($dark-blue, 30%)),
$route-badges: ('crud', lighten($cyan, 15%)), ('all', lighten($teal, 15%)),
('get', lighten($blue, 10%)), ('put', lighten($orange, 10%)),
('post', lighten($green, 10%)), ('delete', lighten($red, 17%)),
('head', lighten($purple, 25%)), ('patch', $yellow),
('options', lighten($dark-blue, 30%)),
('propfind', lighten($custom-gray, 45%)),
('proppatch', lighten($custom-gray, 45%)),
('copy', lighten($custom-gray, 45%)), ('move', lighten($custom-gray, 45%)),
Expand All @@ -141,10 +142,10 @@ $route-badges: ('crud', lighten($cyan, 15%)), ('get', lighten($blue, 10%)),
}
}

// response badges (methods)
$response-badges: ('get', lighten($blue, 10%)), ('4xx', lighten($orange, 10%)),
('2xx', lighten($green, 10%)), ('5xx', lighten($red, 17%)),
('3xx', lighten($purple, 25%)), ('1xx', lighten($custom-gray, 45%));
// response badges (status codes)
$response-badges: ('4xx', lighten($orange, 10%)), ('2xx', lighten($green, 10%)),
('5xx', lighten($red, 17%)), ('3xx', lighten($purple, 25%)),
('1xx', lighten($custom-gray, 45%));
@each $status in $response-badges {
.response-badge-#{nth($status, 1)} {
background-color: #{nth($status, 2)};
Expand Down
153 changes: 153 additions & 0 deletions packages/desktop/test/data/mock-envs/global-route.json
@@ -0,0 +1,153 @@
{
"uuid": "323a25c6-b196-4d27-baf8-8aeb83d87c76",
"lastMigration": 28,
"name": "Global route and rules",
"endpointPrefix": "",
"latency": 0,
"port": 3000,
"routes": [
{
"uuid": "9745a08e-94c2-451e-bccc-b31dc608bb6d",
"method": "all",
"endpoint": "*",
"documentation": "",
"enabled": true,
"responses": [
{
"uuid": "057ec98a-dd5d-4dd8-9af9-a99dd7a5c3f5",
"body": "unauthorized",
"latency": 0,
"statusCode": 403,
"label": "",
"headers": [],
"filePath": "",
"sendFileAsBody": false,
"rules": [
{
"target": "header",
"modifier": "Authorization",
"value": "",
"invert": false,
"operator": "null"
}
],
"rulesOperator": "OR",
"disableTemplating": false,
"fallbackTo404": false,
"default": true,
"databucketID": "",
"bodyType": "INLINE",
"crudKey": "id"
}
],
"responseMode": "FALLBACK",
"type": "http"
},
{
"uuid": "a80d01ac-a3ac-4551-9332-5d3aa1099569",
"type": "http",
"documentation": "",
"method": "get",
"endpoint": "test",
"responses": [
{
"uuid": "9a24ce9f-a5da-465d-9f58-1f624adf3e11",
"body": "okget",
"latency": 0,
"statusCode": 200,
"label": "",
"headers": [],
"bodyType": "INLINE",
"filePath": "",
"databucketID": "",
"sendFileAsBody": false,
"rules": [],
"rulesOperator": "OR",
"disableTemplating": false,
"fallbackTo404": false,
"default": true,
"crudKey": "id"
}
],
"enabled": true,
"responseMode": null
},
{
"uuid": "9e531525-6937-4e35-b6b7-0018c33a73bc",
"type": "http",
"documentation": "",
"method": "post",
"endpoint": "test",
"responses": [
{
"uuid": "8fa6166f-e25d-4e8b-b2d8-ee246bc689d8",
"body": "okpost",
"latency": 0,
"statusCode": 200,
"label": "",
"headers": [],
"bodyType": "INLINE",
"filePath": "",
"databucketID": "",
"sendFileAsBody": false,
"rules": [],
"rulesOperator": "OR",
"disableTemplating": false,
"fallbackTo404": false,
"default": true,
"crudKey": "id"
}
],
"enabled": true,
"responseMode": null
}
],
"proxyMode": false,
"proxyHost": "",
"cors": true,
"headers": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"proxyReqHeaders": [
{
"key": "",
"value": ""
}
],
"proxyResHeaders": [
{
"key": "",
"value": ""
}
],
"proxyRemovePrefix": false,
"hostname": "",
"tlsOptions": {
"enabled": false,
"type": "CERT",
"pfxPath": "",
"certPath": "",
"keyPath": "",
"caPath": "",
"passphrase": ""
},
"data": [],
"folders": [],
"rootChildren": [
{
"type": "route",
"uuid": "9745a08e-94c2-451e-bccc-b31dc608bb6d"
},
{
"type": "route",
"uuid": "a80d01ac-a3ac-4551-9332-5d3aa1099569"
},
{
"type": "route",
"uuid": "9e531525-6937-4e35-b6b7-0018c33a73bc"
}
]
}

0 comments on commit 8bdd8bb

Please sign in to comment.