System Information
- Strapi Version: 3.6.8
- Operating System: Bitnami
- Database: Postgres
- Node Version: 12.20.2
- NPM Version: 8.1.4
- Yarn Version: 1.22.10
Hi all,
I’ve currently set up my Strapi backend with AWS Lightsail and I can use Postman to make the API calls in production however after trying to setup Nginx Proxy to use HTTPS I’m getting an error when trying to load/login the Admin portal. Sorry if this is a relatively easy fix I’m new to Strapi and picking up what a previous team had implemented, they never deployed it prior
My middleware.js file looks like this:
module.exports = {
load: {
before: ["timer", "responseTime", "logger", "cors", "responses", "gzip"],
order: [],
after: ["parser", "router"],
},
settings: {
timer: {
enabled: true,
},
cors: {
enabled: true,
origin: [
"http://localhost:3000",
"https://mywebsite.com",
"http://mywebsite.com",
"http://www.mywebsite.com",
"https://www.mywebsite.com",
"http://api.mywebsite.com",
"https://api.mywebsite.com",
],
},
},
};
My server.js:
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: 'https://api.mywebsite.com',
admin: {
auth: {
secret: env('ADMIN_JWT_SECRET', ''),
},
},
});
And finally my ecosystem.config.js:
module.exports = {
apps: [
{
name: 'app',
script: 'yarn',
args: 'start',
env: {
NODE_ENV: 'production',
DATABASE_HOST: '',
DATABASE_PORT: '5432',
DATABASE_NAME: '',
DATABASE_USERNAME: '',
DATABASE_PASSWORD: ''
},
exp_backoff_restart_delay: 100,
},
],
settings: {
cors: {
enabled: false,
headers: ['*'],
origin: ["http://localhost", "http://www.mywebsite.com", "https://www.mywebsite.com", "http://mywebsite.com", "https://mywebsite.com", "http://api.mywebsite.com", "https://api.mywebsite.com"],
},
},
};
Edit:
Forgot to add the error being presented in Chrome console:
Access to fetch at 'https://api.mywebsite.com/admin/init' from origin 'http://api.mywebsite.com:1337' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
GET https://api.mywebsite.com/admin/init net::ERR_FAILED