ampproject / ampproject/amp-toolbox
options.sourceOriginPattern.test is not a function
- Dominant language
- HTML
- Stars
- 459
- Forks
- 242
- PR merge metrics
- No merged PRs in 30d
Description
I am using `@ampproject/toolbox-cors` for setting cors for on express server.
I get following error
```
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "TypeError: options.sourceOriginPattern.test is not a function",
"reason": {
"errorType": "TypeError",
"errorMessage": "options.sourceOriginPattern.test is not a function",
"stack": [
"TypeError: options.sourceOriginPattern.test is not a function",
" at normalizedHeaders (/var/task/node_modules/@ampproject/toolbox-cors/lib/cors.js:65:69)",
" at Layer.handle [as handle_request] (/var/task/node_modules/express/lib/router/layer.js:95:5)",
" at trim_prefix (/var/task/node_modules/express/lib/router/index.js:317:13)",
" at /var/task/node_modules/express/lib/router/index.js:284:7",
" at Function.process_params (/var/task/node_modules/express/lib/router/index.js:335:12)",
" at next (/var/task/node_modules/express/lib/router/index.js:275:10)",
" at apiGatewayEventParser (/var/task/node_modules/aws-serverless-express/src/middleware.js:22:3)",
" at Layer.handle [as handle_request] (/var/task/node_modules/express/lib/router/layer.js:95:5)",
" at trim_prefix (/var/task/node_modules/express/lib/router/index.js:317:13)",
" at /var/task/node_modules/express/lib/router/index.js:284:7"
]
},
"promise": {},
"stack": [
"Runtime.UnhandledPromiseRejection: TypeError: options.sourceOriginPattern.test is not a function",
" at process. (/var/runtime/index.js:35:15)",
" at process.emit (events.js:310:20)",
" at processPromiseRejections (internal/process/promises.js:209:33)",
" at processTicksAndRejections (internal/process/task_queues.js:98:32)"
]
}
```
If I don't use `sourceOriginPattern` then it works fine. When I use it then I get error from above.
```
app.use(ampCors({
verbose: true,
sourceOriginPattern: "/https:\/\/apoorv\.blog$/",
verifyOrigin: false
}))
```
Contributor guide
Research direction
Start at lib/cors.js:65, where normalizedHeaders calls options.sourceOriginPattern.test, and compare that entry point with the app.use(ampCors(...)) configuration shown in the issue. Confirm the expected type for sourceOriginPattern and verify that the middleware no longer throws when the documented configuration is used.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100