# Expires map
map $sent_http_content_type $expires {
    default                             off;
    text/html                           @1h;
    text/css                            @24h;
    application/javascript              @24h;
    ~image/                             @24h;
    font/font-woff                      @24h;
    font/font-woff2                     @24h;
    font/opentype                       @24h;
    font/truetype                       @24h;
    font/woff                           @24h;
    font/woff2                          @24h;
    application/vnd.ms-fontobject       @24h;
}

# FORCE HTTPS
server {
    listen 80;
    listen [::]:80;
    server_name widget.bambuyo.com;
    return 301 https://widget.bambuyo.com$request_uri;
}

# FINAL HTTPS DONE
server {

    # https configuration
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    # config to enable HSTS(HTTP Strict Transport Security)
    add_header Strict-Transport-Security "max-age=63072000; includeSubdomains;";

    # certificates
    ssl_certificate /etc/letsencrypt/live/widget.bambuyo.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/widget.bambuyo.com/privkey.pem; # managed by Certbot

    # domain name
    server_name widget.bambuyo.com;

    # Absolute path to your website root on the filesystem
    root /var/www/bambuyo-widget/;

    # logs
    access_log  /var/log/nginx/bambuyo-widget.access.log;
    error_log  /var/log/nginx/bambuyo-widget.error.log;

    # NO CACHE for app.js - critical for widget updates
    location ~* /js/app\.js$ {
        expires off;
        add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
        add_header Pragma "no-cache";
    }

}
