Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

Commit

Permalink
express: move authentication middleware earlier
Browse files Browse the repository at this point in the history
Otherwise, it doesn't apply to views.
  • Loading branch information
vincentbernat committed Feb 10, 2017
1 parent 5719649 commit d9f4a16
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ if (config.get('forcessl')) {
logger.express.access(app);
logger.express.error(app);

// Authentication
if (config.get('auth:enabled')) {
var basic = auth.basic({
realm: config.get('auth:realm')
}, function(username, password, callback) {
// Custom authentication method.
callback(username === config.get('auth:username') &&
password === config.get('auth:password'));
});
app.use(auth.connect(basic));
}

// Asset handling
var assets = {};
try {
Expand Down Expand Up @@ -88,17 +100,6 @@ app.get('/receiver-:grade', function(req, res) {
app.use(expressStatic(config.get('path:static'), { extensions: ['html'] }));
app.use(methodOverride());

if (config.get('auth:enabled')) {
var basic = auth.basic({
realm: config.get('auth:realm')
}, function(username, password, callback) {
// Custom authentication method.
callback(username === config.get('auth:username') &&
password === config.get('auth:password'));
});
app.use(auth.connect(basic));
}

if (app.get('env') === 'development') {
app.set('view cache', false);
app.use(expressErrorHandler());
Expand Down

0 comments on commit d9f4a16

Please sign in to comment.