amp-toolbox icon indicating copy to clipboard operation
amp-toolbox copied to clipboard

options.sourceOriginPattern.test is not a function

Open apoorvmote opened this issue 4 years ago • 0 comments

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.<anonymous> (/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
}))

apoorvmote avatar Jul 16 '20 11:07 apoorvmote