This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace MustCompile with Compile for non-hardcoded regexes (#238)
* Add release yaml to workflows Signed-off-by: thepetk <thepetk@gmail.com> * Remove autogeneration of release notes Signed-off-by: thepetk <thepetk@gmail.com> * Replace MustCompile for dynamic strings Signed-off-by: thepetk <thepetk@gmail.com> * Add expressjs test resource Signed-off-by: thepetk <thepetk@gmail.com> * Add test case for regexp dynamic strings error handling Signed-off-by: thepetk <thepetk@gmail.com> * Remove release yaml from non related issue Signed-off-by: thepetk <thepetk@gmail.com> * Update count of tests Signed-off-by: thepetk <thepetk@gmail.com> --------- Signed-off-by: thepetk <thepetk@gmail.com>
- Loading branch information
Showing
14 changed files
with
1,213 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2020 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export interface Config { | ||
/** | ||
* A list of forwarding-proxies. Each key is a route to match, | ||
* below the prefix that the proxy plugin is mounted on. It must | ||
* start with a '/'. | ||
*/ | ||
proxy?: { | ||
[key: string]: | ||
| string | ||
| { | ||
/** | ||
* Target of the proxy. Url string to be parsed with the url module. | ||
*/ | ||
target: string; | ||
/** | ||
* Object with extra headers to be added to target requests. | ||
*/ | ||
headers?: Partial<{ | ||
/** @visibility secret */ | ||
Authorization: string; | ||
/** @visibility secret */ | ||
authorization: string; | ||
/** @visibility secret */ | ||
'X-Api-Key': string; | ||
/** @visibility secret */ | ||
'x-api-key': string; | ||
[key: string]: string; | ||
}>; | ||
/** | ||
* Changes the origin of the host header to the target URL. Default: true. | ||
*/ | ||
changeOrigin?: boolean; | ||
/** | ||
* Rewrite target's url path. Object-keys will be used as RegExp to match paths. | ||
* If pathRewrite is not specified, it is set to a single rewrite that removes the entire prefix and route. | ||
*/ | ||
pathRewrite?: { [regexp: string]: string }; | ||
/** | ||
* Limit the forwarded HTTP methods, for example allowedMethods: ['GET'] to enforce read-only access. | ||
*/ | ||
allowedMethods?: string[]; | ||
/** | ||
* Limit the forwarded HTTP methods. By default, only the headers that are considered safe for CORS | ||
* and headers that are set by the proxy will be forwarded. | ||
*/ | ||
allowedHeaders?: string[]; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"name": "expressjs", | ||
"description": "test resources", | ||
"version": "0.2.40-next.2", | ||
"main": "src/index.ts", | ||
"types": "src/index.ts", | ||
"license": "Apache-2.0", | ||
"publishConfig": { | ||
"access": "public", | ||
"main": "dist/index.cjs.js", | ||
"types": "dist/index.d.ts", | ||
"alphaTypes": "dist/index.alpha.d.ts" | ||
}, | ||
"backstage": { | ||
"role": "backend-plugin" | ||
}, | ||
"homepage": "https://backstage.io", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/backstage/backstage", | ||
"directory": "plugins/proxy-backend" | ||
}, | ||
"keywords": [ | ||
"backstage" | ||
], | ||
"dependencies": { | ||
"@backstage/backend-common": "workspace:^", | ||
"@backstage/backend-plugin-api": "workspace:^", | ||
"@backstage/config": "workspace:^", | ||
"@types/express": "^4.17.6", | ||
"express": "^4.17.1", | ||
"express-promise-router": "^4.1.0", | ||
"http-proxy-middleware": "^2.0.0", | ||
"morgan": "^1.10.0", | ||
"uuid": "^8.0.0", | ||
"winston": "^3.2.1", | ||
"yaml": "^2.0.0", | ||
"yn": "^4.0.0", | ||
"yup": "^0.32.9" | ||
}, | ||
"devDependencies": { | ||
"@backstage/cli": "workspace:^", | ||
"@types/http-proxy-middleware": "^0.19.3", | ||
"@types/supertest": "^2.0.8", | ||
"@types/uuid": "^8.0.0", | ||
"@types/yup": "^0.29.13", | ||
"msw": "^1.0.0", | ||
"supertest": "^6.1.3" | ||
}, | ||
"files": [ | ||
"dist", | ||
"config.d.ts", | ||
"alpha" | ||
], | ||
"configSchema": "config.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2020 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* A Backstage backend plugin that helps you set up proxy endpoints in the backend | ||
* | ||
* @packageDocumentation | ||
*/ | ||
|
||
export * from './service'; | ||
export { proxyPlugin } from './plugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2023 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { loggerToWinstonLogger } from '@backstage/backend-common'; | ||
import { | ||
createBackendPlugin, | ||
coreServices, | ||
} from '@backstage/backend-plugin-api'; | ||
import { createRouter } from './service/router'; | ||
|
||
/** | ||
* The proxy backend plugin. | ||
* | ||
* @alpha | ||
*/ | ||
export const proxyPlugin = createBackendPlugin( | ||
(options?: { | ||
skipInvalidProxies?: boolean; | ||
reviveConsumedRequestBodies?: boolean; | ||
}) => ({ | ||
pluginId: 'proxy', | ||
register(env) { | ||
env.registerInit({ | ||
deps: { | ||
config: coreServices.config, | ||
discovery: coreServices.discovery, | ||
logger: coreServices.logger, | ||
httpRouter: coreServices.httpRouter, | ||
}, | ||
async init({ config, discovery, logger, httpRouter }) { | ||
httpRouter.use( | ||
await createRouter({ | ||
config, | ||
discovery, | ||
logger: loggerToWinstonLogger(logger), | ||
skipInvalidProxies: options?.skipInvalidProxies, | ||
reviveConsumedRequestBodies: options?.reviveConsumedRequestBodies, | ||
}), | ||
); | ||
}, | ||
}); | ||
}, | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2020 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { getRootLogger } from '@backstage/backend-common'; | ||
import yn from 'yn'; | ||
import { startStandaloneServer } from './service/standaloneServer'; | ||
|
||
const port = process.env.PLUGIN_PORT ? Number(process.env.PLUGIN_PORT) : 7007; | ||
const enableCors = yn(process.env.PLUGIN_CORS, { default: false }); | ||
const logger = getRootLogger(); | ||
|
||
startStandaloneServer({ port, enableCors, logger }).catch(err => { | ||
logger.error(err); | ||
process.exit(1); | ||
}); | ||
|
||
process.on('SIGINT', () => { | ||
logger.info('CTRL+C pressed; exiting.'); | ||
process.exit(0); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2020 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export type { RouterOptions } from './router'; | ||
export { createRouter } from './router'; |
Oops, something went wrong.