@@ -36,13 +36,13 @@ function checkIfIconsExistForApps(apps, iconsFolder) {
3636 const iconName = currentApp . iconName ;
3737 const path = iconsFolder + '/' + iconName ;
3838
39- fs . stat ( path , function ( err ) {
39+ fs . stat ( path , function ( err ) {
4040 if ( err ) {
41- if ( 'ENOENT' == err . code ) { // file does not exist
42- console . warn ( 'Icon with file name: ' + iconName + ' couldn\'t be found in icons folder!' ) ;
41+ if ( 'ENOENT' == err . code ) {
42+ // file does not exist
43+ console . warn ( 'Icon with file name: ' + iconName + " couldn't be found in icons folder!" ) ;
4344 } else {
44- console . log (
45- 'An error occurd while checking for icons, please check permission!' ) ;
45+ console . log ( 'An error occurd while checking for icons, please check permission!' ) ;
4646 }
4747 } else {
4848 //every thing was ok so for example you can read it and send it to client
@@ -51,37 +51,42 @@ function checkIfIconsExistForApps(apps, iconsFolder) {
5151 }
5252}
5353
54- module . exports = function ( config , options ) {
54+ module . exports = function ( config , options ) {
5555 options = options || { } ;
5656 const app = express ( ) ;
5757 // Serve public files.
58- app . use ( express . static ( path . join ( __dirname , 'public' ) ) ) ;
58+ app . use ( express . static ( path . join ( __dirname , 'public' ) ) ) ;
5959
6060 // Allow setting via middleware
6161 if ( config . trustProxy && app . disabled ( 'trust proxy' ) ) {
6262 app . enable ( 'trust proxy' ) ;
6363 }
6464
6565 // wait for app to mount in order to get mountpath
66- app . on ( 'mount' , function ( ) {
66+ app . on ( 'mount' , function ( ) {
6767 const mountPath = getMount ( app . mountpath ) ;
6868 const users = config . users ;
6969 const useEncryptedPasswords = config . useEncryptedPasswords ? true : false ;
7070 const authInstance = new Authentication ( users , useEncryptedPasswords , mountPath ) ;
71- authInstance . initialize ( app , { cookieSessionSecret : options . cookieSessionSecret , cookieSessionMaxAge : options . cookieSessionMaxAge } ) ;
71+ authInstance . initialize ( app , {
72+ cookieSessionSecret : options . cookieSessionSecret ,
73+ cookieSessionMaxAge : options . cookieSessionMaxAge ,
74+ } ) ;
7275
7376 // CSRF error handler
7477 app . use ( function ( err , req , res , next ) {
75- if ( err . code !== 'EBADCSRFTOKEN' ) { return next ( err ) }
78+ if ( err . code !== 'EBADCSRFTOKEN' ) {
79+ return next ( err ) ;
80+ }
7681
7782 // handle CSRF token errors here
78- res . status ( 403 )
79- res . send ( 'form tampered with' )
83+ res . status ( 403 ) ;
84+ res . send ( 'form tampered with' ) ;
8085 } ) ;
8186
8287 // Serve the configuration.
83- app . get ( '/parse-dashboard-config.json' , function ( req , res ) {
84- const apps = config . apps . map ( ( app ) => Object . assign ( { } , app ) ) ; // make a copy
88+ app . get ( '/parse-dashboard-config.json' , function ( req , res ) {
89+ const apps = config . apps . map ( app => Object . assign ( { } , app ) ) ; // make a copy
8590 const response = {
8691 apps : apps ,
8792 newFeaturesInLatestVersion : newFeaturesInLatestVersion ,
@@ -96,12 +101,18 @@ module.exports = function(config, options) {
96101 if ( ! options . dev && ! requestIsLocal ) {
97102 if ( ! req . secure && ! options . allowInsecureHTTP ) {
98103 //Disallow HTTP requests except on localhost, to prevent the master key from being transmitted in cleartext
99- return res . send ( { success : false , error : 'Parse Dashboard can only be remotely accessed via HTTPS' } ) ;
104+ return res . send ( {
105+ success : false ,
106+ error : 'Parse Dashboard can only be remotely accessed via HTTPS' ,
107+ } ) ;
100108 }
101109
102110 if ( ! users ) {
103111 //Accessing the dashboard over the internet can only be done with username and password
104- return res . send ( { success : false , error : 'Configure a user to access Parse Dashboard remotely' } ) ;
112+ return res . send ( {
113+ success : false ,
114+ error : 'Configure a user to access Parse Dashboard remotely' ,
115+ } ) ;
105116 }
106117 }
107118 const authentication = req . user ;
@@ -111,7 +122,7 @@ module.exports = function(config, options) {
111122 const isReadOnly = authentication && authentication . isReadOnly ;
112123 // User is full read-only, replace the masterKey by the read-only one
113124 if ( isReadOnly ) {
114- response . apps = response . apps . map ( ( app ) => {
125+ response . apps = response . apps . map ( app => {
115126 app . masterKey = app . readOnlyMasterKey ;
116127 if ( ! app . masterKey ) {
117128 throw new Error ( 'You need to provide a readOnlyMasterKey to use read-only features.' ) ;
@@ -131,7 +142,7 @@ module.exports = function(config, options) {
131142 app . masterKey = app . readOnlyMasterKey ;
132143 }
133144 return isSame ;
134- } )
145+ } ) ;
135146 } ) ;
136147 }
137148 // They provided correct auth
@@ -167,13 +178,15 @@ module.exports = function(config, options) {
167178 }
168179 } catch ( e ) {
169180 // Directory doesn't exist or something.
170- console . warn ( 'Iconsfolder at path: ' + config . iconsFolder +
171- ' not found!' ) ;
181+ console . warn ( 'Iconsfolder at path: ' + config . iconsFolder + ' not found!' ) ;
172182 }
173183 }
174184
175- app . get ( '/login' , csrf ( ) , function ( req , res ) {
176- const redirectURL = req . url . includes ( '?redirect=' ) && req . url . split ( '?redirect=' ) [ 1 ] . length > 1 && req . url . split ( '?redirect=' ) [ 1 ] ;
185+ app . get ( '/login' , csrf ( ) , function ( req , res ) {
186+ const redirectURL =
187+ req . url . includes ( '?redirect=' ) &&
188+ req . url . split ( '?redirect=' ) [ 1 ] . length > 1 &&
189+ req . url . split ( '?redirect=' ) [ 1 ] ;
177190 if ( ! users || ( req . user && req . user . isAuthenticated ) ) {
178191 return res . redirect ( `${ mountPath } ${ redirectURL || 'apps' } ` ) ;
179192 }
@@ -182,7 +195,7 @@ module.exports = function(config, options) {
182195 if ( errors && errors . length ) {
183196 errors = `<div id="login_errors" style="display: none;">
184197 ${ errors . join ( ' ' ) }
185- </div>`
198+ </div>` ;
186199 }
187200 res . send ( `<!DOCTYPE html>
188201 <html>
@@ -205,7 +218,7 @@ module.exports = function(config, options) {
205218 } ) ;
206219
207220 // For every other request, go to index.html. Let client-side handle the rest.
208- app . get ( '/*' , function ( req , res ) {
221+ app . get ( '/*' , function ( req , res , next ) {
209222 if ( users && ( ! req . user || ! req . user . isAuthenticated ) ) {
210223 const redirect = req . url . replace ( '/login' , '' ) ;
211224 if ( redirect . length > 1 ) {
@@ -216,7 +229,8 @@ module.exports = function(config, options) {
216229 if ( users && req . user && req . user . matchingUsername ) {
217230 res . append ( 'username' , req . user . matchingUsername ) ;
218231 }
219- res . send ( `<!DOCTYPE html>
232+ if ( ! req . path . startsWith ( '/v2' ) ) {
233+ res . send ( `<!DOCTYPE html>
220234 <html>
221235 <head>
222236 <link rel="shortcut icon" type="image/x-icon" href="${ mountPath } favicon.ico" />
@@ -232,8 +246,11 @@ module.exports = function(config, options) {
232246 </body>
233247 </html>
234248 ` ) ;
249+ } else {
250+ next ( ) ;
251+ }
235252 } ) ;
236253 } ) ;
237254
238255 return app ;
239- }
256+ } ;
0 commit comments