My lambda api redirects url to another url. To document this on swagger UI. It gives CORS Error. this works fine with postman or from browser
Error message
TypeError: cross-origin to google.com denied by CORS policy. Origini null not allowd by Access-contrl-allow-origin
Note : I am using open api version version 2:0
my endpoint : https://my-domain/123456 -> redirects to google.com
serverless.yml
event:
-http:
path: /
method: ANY
cors:true
app.js
app.use(cors())
my swagger.yml
/{shortUrl}:
get:
tags:
- 'Redirection'
summary: 'Redirect short URL -> Original'
description: 'This route redirects user to original URL website when a get is sent to trimified URL'
produces:
- 'text/plain; charset=utf-8'
parameters:
- name: 'shortUrl'
in: 'path'
description: 'ID of short URL'
required: true
type: 'string'
responses:
'400':
description: 'Invalid URL'
schema:
$ref: '#/responseDefinitions/UserErrorResponse'
'201':
description: 'OK'
schema:
$ref: '#/responseDefinitions/ApiResponse'
'500':
description: 'Internal Server Error'
schema:
$ref: '#/responseDefinitions/ServerErrorResponse'