Skip to content

Commit

Permalink
Add basic auth to storybook (github#20955)
Browse files Browse the repository at this point in the history
* Add basic auth to storybook

* Update index.js

* Update index.js
  • Loading branch information
heiskr authored Aug 18, 2021
1 parent d565050 commit 8d7bb82
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
12 changes: 8 additions & 4 deletions middleware/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import express from 'express'
import basicAuth from 'express-basic-auth'
import instrument from '../lib/instrument-middleware.js'
import haltOnDroppedConnection from './halt-on-dropped-connection.js'
import abort from './abort.js'
Expand Down Expand Up @@ -61,6 +62,7 @@ import renderPage from './render-page.js'
const { NODE_ENV } = process.env
const isDevelopment = NODE_ENV === 'development'
const isTest = NODE_ENV === 'test' || process.env.GITHUB_ACTIONS === 'true'
const isProduction = NODE_ENV === 'production' && process.env.HEROKU_PRODUCTION_APP

// Catch unhandled promise rejections and passing them to Express's error handler
// https://medium.com/@Abazhenov/using-async-await-in-express-with-node-8-b8af872c0016
Expand Down Expand Up @@ -143,16 +145,18 @@ export default function (app) {
instrument(archivedEnterpriseVersionsAssets, './archived-enterprise-versions-assets')
)
)
app.use(
'/storybook',
app.use('/storybook', [
(isProduction &&
basicAuth({ users: { octocat: process.env.STORYBOOK_PASSWORD }, challenge: true })) ||
((req, res, next) => next()),
express.static('storybook', {
index: false,
etag: false,
immutable: true,
lastModified: false,
maxAge: '1 day', // Relatively short in case we update index.html
})
)
}),
])
app.use(
'/assets',
express.static('assets', {
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dayjs": "^1.10.6",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"express-basic-auth": "^1.2.0",
"express-rate-limit": "^5.3.0",
"express-timeout-handler": "^2.2.2",
"flat": "^5.0.2",
Expand Down

0 comments on commit 8d7bb82

Please sign in to comment.