netlify / ask-netlify

A place to submit questions for Netlify to answer in tutorials, podcasts and blog posts
https://ask.netlify.com
32 stars 8 forks source link

Password protection for subdomains and specific pages #74

Closed iamskok closed 3 years ago

iamskok commented 4 years ago

About me

My question in a little more detail

I'm trying to find a way to set password protection for subdomains and specific pages for my Gatsby website. I used netlify.toml file to switch _headers files for production, branch-deploy and preview-deploy contexts, but it's not working (headers are not being set). Did I miss anything?

My folder structure looks like this:

... other files
├── public
│   ├── _branchdeploy_headers
│   ├── _deploypreview_headers
│   └── _headers
├── static
│   ├── _branchdeploy_headers
│   ├── _deploypreview_headers
│   └── _headers
└── netlify.toml

Netlify.toml:

[context.branch-deploy]
  command = "yarn build && cp static/_branchdeploy_headers public/_headers"

[context.deploy-preview]
  command = "yarn build && cp static/_deploypreview_headers public/_headers"

_headers:

/style-guide
  Basic-Auth: admin:password

_branchdeploy_headers & _deploypreview_headers:

/*
  Basic-Auth: admin:password

Gatsby info:

  System:
    OS: macOS 10.15.3
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 11.14.0 - ~/.nvm/versions/node/v11.14.0/bin/node
    Yarn: 1.19.2 - ~/.nvm/versions/node/v11.14.0/bin/yarn
    npm: 6.11.3 - ~/.nvm/versions/node/v11.14.0/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 79.0.3945.130
    Firefox: 72.0.2
    Safari: 13.0.5
  npmPackages:
    gatsby: ^2.19.17 => 2.19.17
    gatsby-background-image: ^0.9.12 => 0.9.17
    gatsby-cli: ^2.5.12 => 2.8.29
    gatsby-image: ^2.0.29 => 2.2.41
    gatsby-plugin-google-tagmanager: ^2.1.25 => 2.1.25
    gatsby-plugin-manifest: ^2.2.41 => 2.2.41
    gatsby-plugin-netlify: ^2.1.32 => 2.1.32
    gatsby-plugin-netlify-headers: ^1.0.1 => 1.0.1
    gatsby-plugin-offline: ^3.0.34 => 3.0.34
    gatsby-plugin-react-helmet: ^3.0.6 => 3.1.22
    gatsby-plugin-react-svg: ^3.0.0 => 3.0.0
    gatsby-plugin-robots-txt: ^1.5.0 => 1.5.0
    gatsby-plugin-sass: ^2.0.11 => 2.1.28
    gatsby-plugin-sharp: ^2.0.20 => 2.4.5
    gatsby-plugin-sitemap: ^2.2.27 => 2.2.27
    gatsby-remark-responsive-iframe: ^2.0.9 => 2.2.32
    gatsby-source-filesystem: ^2.0.20 => 2.1.48
    gatsby-transformer-sharp: ^2.1.13 => 2.3.14
  npmGlobalPackages:
    gatsby-cli: 2.8.29
    gatsby: 2.5.7
Pieparker commented 3 years ago

Hey there! If you still require help, can I ask that you visit Netlify Community and share your question there? You may wish to search and see if this has been asked before!