@@ -4,13 +4,27 @@ const cors = require('cors');
4
4
5
5
const passport = require ( 'passport' ) ;
6
6
const passportAzureAd = require ( 'passport-azure-ad' ) ;
7
+ const NodeCache = require ( 'node-cache' ) ;
7
8
8
- const authConfig = require ( './authConfig' ) ;
9
+ const authConfig = require ( './authConfig.json ' ) ;
9
10
const router = require ( './routes/router' ) ;
10
11
const routeGuard = require ( './auth/guard' ) ;
11
12
12
- const app = express ( ) ;
13
+ /**
14
+ * IMPORTANT: In case of overage, group list is cached for 1 hr by default, and thus cached groups
15
+ * will miss any changes to a users group membership for this duration. For capturing real-time
16
+ * changes to a user's group membership, consider implementing Microsoft Graph change notifications.
17
+ * For more information, visit: https://learn.microsoft.com/graph/api/resources/webhooks
18
+ */
19
+ const nodeCache = new NodeCache ( {
20
+ stdTTL : authConfig . cacheTTL , // in seconds
21
+ checkperiod : 60 * 100 ,
22
+ deleteOnExpire : true
23
+ } ) ;
24
+
25
+ const cacheProvider = require ( './utils/cacheProvider' ) ( nodeCache ) ;
13
26
27
+ const app = express ( ) ;
14
28
/**
15
29
* Enable CORS middleware. In production, modify as to allow only designated origins and methods.
16
30
* If you are using Azure App Service, we recommend removing the line below and configure CORS on the App Service itself.
@@ -89,7 +103,6 @@ app.use('/api', (req, res, next) => {
89
103
return res . status ( 401 ) . json ( { error : err . message } ) ;
90
104
}
91
105
92
-
93
106
if ( ! user ) {
94
107
// If no user object found, send a 401 response.
95
108
return res . status ( 401 ) . json ( { error : 'Unauthorized' } ) ;
@@ -103,21 +116,21 @@ app.use('/api', (req, res, next) => {
103
116
} ) ( req , res , next ) ;
104
117
} ,
105
118
106
- routeGuard ( authConfig . accessMatrix ) ,
107
- router ,
108
- ( err , req , res , next ) => {
109
- /**
110
- * Add your custom error handling logic here. For more information, see:
111
- * http://expressjs.com/en/guide/error-handling.html
112
- */
113
-
114
- // set locals, only providing error in development
115
- res . locals . message = err . message ;
116
- res . locals . error = req . app . get ( 'env' ) === 'development' ? err : { } ;
117
-
118
- // send error response
119
- res . status ( err . status || 500 ) . send ( err ) ;
120
- }
119
+ routeGuard ( authConfig . accessMatrix , cacheProvider ) ,
120
+ router ,
121
+ ( err , req , res , next ) => {
122
+ /**
123
+ * Add your custom error handling logic here. For more information, see:
124
+ * http://expressjs.com/en/guide/error-handling.html
125
+ */
126
+
127
+ // set locals, only providing error in development
128
+ res . locals . message = err . message ;
129
+ res . locals . error = req . app . get ( 'env' ) === 'development' ? err : { } ;
130
+
131
+ // send error response
132
+ res . status ( err . status || 500 ) . send ( err ) ;
133
+ }
121
134
) ;
122
135
123
136
const port = process . env . PORT || 5000 ;
0 commit comments