@@ -36,13 +36,13 @@ function checkIfIconsExistForApps(apps, iconsFolder) {
36
36
const iconName = currentApp . iconName ;
37
37
const path = iconsFolder + '/' + iconName ;
38
38
39
- fs . stat ( path , function ( err ) {
39
+ fs . stat ( path , function ( err ) {
40
40
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!" ) ;
43
44
} 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!' ) ;
46
46
}
47
47
} else {
48
48
//every thing was ok so for example you can read it and send it to client
@@ -51,37 +51,42 @@ function checkIfIconsExistForApps(apps, iconsFolder) {
51
51
}
52
52
}
53
53
54
- module . exports = function ( config , options ) {
54
+ module . exports = function ( config , options ) {
55
55
options = options || { } ;
56
56
const app = express ( ) ;
57
57
// Serve public files.
58
- app . use ( express . static ( path . join ( __dirname , 'public' ) ) ) ;
58
+ app . use ( express . static ( path . join ( __dirname , 'public' ) ) ) ;
59
59
60
60
// Allow setting via middleware
61
61
if ( config . trustProxy && app . disabled ( 'trust proxy' ) ) {
62
62
app . enable ( 'trust proxy' ) ;
63
63
}
64
64
65
65
// wait for app to mount in order to get mountpath
66
- app . on ( 'mount' , function ( ) {
66
+ app . on ( 'mount' , function ( ) {
67
67
const mountPath = getMount ( app . mountpath ) ;
68
68
const users = config . users ;
69
69
const useEncryptedPasswords = config . useEncryptedPasswords ? true : false ;
70
70
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
+ } ) ;
72
75
73
76
// CSRF error handler
74
77
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
+ }
76
81
77
82
// 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' ) ;
80
85
} ) ;
81
86
82
87
// 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
85
90
const response = {
86
91
apps : apps ,
87
92
newFeaturesInLatestVersion : newFeaturesInLatestVersion ,
@@ -96,12 +101,18 @@ module.exports = function(config, options) {
96
101
if ( ! options . dev && ! requestIsLocal ) {
97
102
if ( ! req . secure && ! options . allowInsecureHTTP ) {
98
103
//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
+ } ) ;
100
108
}
101
109
102
110
if ( ! users ) {
103
111
//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
+ } ) ;
105
116
}
106
117
}
107
118
const authentication = req . user ;
@@ -111,7 +122,7 @@ module.exports = function(config, options) {
111
122
const isReadOnly = authentication && authentication . isReadOnly ;
112
123
// User is full read-only, replace the masterKey by the read-only one
113
124
if ( isReadOnly ) {
114
- response . apps = response . apps . map ( ( app ) => {
125
+ response . apps = response . apps . map ( app => {
115
126
app . masterKey = app . readOnlyMasterKey ;
116
127
if ( ! app . masterKey ) {
117
128
throw new Error ( 'You need to provide a readOnlyMasterKey to use read-only features.' ) ;
@@ -131,7 +142,7 @@ module.exports = function(config, options) {
131
142
app . masterKey = app . readOnlyMasterKey ;
132
143
}
133
144
return isSame ;
134
- } )
145
+ } ) ;
135
146
} ) ;
136
147
}
137
148
// They provided correct auth
@@ -167,13 +178,15 @@ module.exports = function(config, options) {
167
178
}
168
179
} catch ( e ) {
169
180
// 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!' ) ;
172
182
}
173
183
}
174
184
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 ] ;
177
190
if ( ! users || ( req . user && req . user . isAuthenticated ) ) {
178
191
return res . redirect ( `${ mountPath } ${ redirectURL || 'apps' } ` ) ;
179
192
}
@@ -182,7 +195,7 @@ module.exports = function(config, options) {
182
195
if ( errors && errors . length ) {
183
196
errors = `<div id="login_errors" style="display: none;">
184
197
${ errors . join ( ' ' ) }
185
- </div>`
198
+ </div>` ;
186
199
}
187
200
res . send ( `<!DOCTYPE html>
188
201
<html>
@@ -205,7 +218,7 @@ module.exports = function(config, options) {
205
218
} ) ;
206
219
207
220
// 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 ) {
209
222
if ( users && ( ! req . user || ! req . user . isAuthenticated ) ) {
210
223
const redirect = req . url . replace ( '/login' , '' ) ;
211
224
if ( redirect . length > 1 ) {
@@ -216,7 +229,8 @@ module.exports = function(config, options) {
216
229
if ( users && req . user && req . user . matchingUsername ) {
217
230
res . append ( 'username' , req . user . matchingUsername ) ;
218
231
}
219
- res . send ( `<!DOCTYPE html>
232
+ if ( ! req . path . startsWith ( '/v2' ) ) {
233
+ res . send ( `<!DOCTYPE html>
220
234
<html>
221
235
<head>
222
236
<link rel="shortcut icon" type="image/x-icon" href="${ mountPath } favicon.ico" />
@@ -232,8 +246,11 @@ module.exports = function(config, options) {
232
246
</body>
233
247
</html>
234
248
` ) ;
249
+ } else {
250
+ next ( ) ;
251
+ }
235
252
} ) ;
236
253
} ) ;
237
254
238
255
return app ;
239
- }
256
+ } ;
0 commit comments