How to avoid cross-origin error from AWS EC2 instance?

Viewed 36

I deployed a Server on AWS EC2 instance. UI part is deployed on S3 bucket as a static website. After send a POST request from S3 to EC2 instance I get strict-origin-when-cross-origin error. The back-end app was created on Nest.js and CORS is already enabled.

Can somebody explain what I do wrong?

Sсhema

Schema

UI with error

UI

Nest.js part

async function bootstrap() {
    const appOptions = { bodyParser: false }
    const app = await NestFactory.create(AppModule, appOptions)
    app.enableCors()

    app.useWebSocketAdapter(new RedisIoAdapter(app))

    app.useGlobalPipes(new ValidationPipe({ transform: true }))
    app.setGlobalPrefix('api')

    app.use(bodyParser.json({ limit: '10mb', verify: rawBodyBuffer }))
    app.use(bodyParser.urlencoded({ limit: '20mb', extended: true, verify: rawBodyBuffer }))

    await app.listen(3000)
}
bootstrap()

2 Answers

I think this could be an issue of https ans http different.

Your website is https://www.site.de That mean front is using an https protocal to secure a communication between server. But the Server is not using a https protocal. So It could case cors error

There's a way to apply an https on AWS

Use Rout53 and Certificate Manager.

These two will help to use https to you ec2

I had the similar issue a few weeks ago. It's a problem with AWS health checks.

Try to add GET / route if you don't have it yet. Hope it helped you.

Related