Skip to main content

Install

Dành cho dev services. Sau khi config xong thì dùng url http://localhost:8081/api..., không cần setup cors cho express.

Cài cho Macos

brew install nginx
tip

Nếu chưa có brew, install tại https://brew.sh/

Mở terminal

cd /opt/homebrew/etc/nginx/
mkdir config
nano config/cors.conf

sau đó paste:

add_header 'Access-Control-Allow-Origin' "*" always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;

ctrl + o, enterctrl + x để lưu và thoát

brew services start nginx
mkdir servers
nano servers/builder.conf

paste file:

server {
listen [::]:8081;
listen 8081;
server_name localhost;

client_max_body_size 100M;

location /api/v1/compiler {
proxy_pass http://localhost:1238/api/v1/compiler;
include config/cors.conf;
}
location /api/v1/style {
proxy_pass http://localhost:1235/api/v1/style;
include config/cors.conf;
}
location /api/v1/media {
proxy_pass http://localhost:1236/api/v1/media;
include config/cors.conf;
}
location /api/v1/shopify-data {
proxy_pass http://localhost:1239/api/v1/shopify-data;
include config/cors.conf;
}
location /service/proxy {
proxy_pass http://localhost:1240/service/proxy;
}
}

ctrl + o, enterctrl + x để lưu và thoát

chạy lệnh

brew services reload nginx
tip

Không đặt app chạy port 8080 và 8081, vì sẽ bị tranh cổng với nginx