@@ -29,6 +29,7 @@ module.exports = function(RED) {
29
29
30
30
function getMime ( filename ) {
31
31
var ext = filename . match ( / \. [ ^ . ] + $ / ) ;
32
+ if ( typeof ext == 'object' ) ext = ext [ 0 ] ;
32
33
var isBinary = false ;
33
34
var _mimeType ;
34
35
@@ -430,6 +431,43 @@ module.exports = function(RED) {
430
431
res . send ( 'var socketUrl = ""; var socketSession = "' + '' + '"; var socketNamespace = "vis";' ) ;
431
432
} ) ;
432
433
434
+ // user css files
435
+ RED . httpNode . get ( '/vis.0/*' , function ( req , res , next ) {
436
+ var file ;
437
+ var f = req . url . split ( '?' ) ;
438
+
439
+ f [ 0 ] = f [ 0 ] . substring ( 7 ) ;
440
+
441
+ file = base + 'vis/' + f [ 0 ] ;
442
+ var info = getMime ( file ) ;
443
+ if ( fs . existsSync ( file ) ) {
444
+ res . contentType ( info . mimeType || 'text/javascript' ) ;
445
+ var buffer = fs . readFileSync ( file ) ;
446
+ res . send ( buffer ) ;
447
+ } else {
448
+ if ( info . ext == '.css' ) {
449
+ res . contentType ( 'text/css' ) ;
450
+ res . send ( '' ) ;
451
+ } else {
452
+ res . status ( 404 ) . send ( '404 Not found. File ' + req . url + ' not found' ) ;
453
+ }
454
+ }
455
+ } ) ;
456
+
457
+ // web libraries
458
+ RED . httpNode . get ( '/lib/*' , function ( req , res , next ) {
459
+ var f = req . url . split ( '?' ) ;
460
+ var file = __dirname + '/node_modules/iobroker.web/www' + f [ 0 ] ;
461
+ var info = getMime ( file ) ;
462
+ if ( fs . existsSync ( file ) ) {
463
+ res . contentType ( info . mimeType || 'text/javascript' ) ;
464
+ var buffer = fs . readFileSync ( file ) ;
465
+ res . send ( buffer ) ;
466
+ } else {
467
+ res . status ( 404 ) . send ( '404 Not found. File ' + req . url + ' not found' ) ;
468
+ }
469
+ } ) ;
470
+
433
471
RED . httpNode . get ( '/vis/*' , function ( req , res , next ) {
434
472
var file ;
435
473
var f = req . url . split ( '?' ) ;
@@ -439,7 +477,11 @@ module.exports = function(RED) {
439
477
} else {
440
478
f [ 0 ] = f [ 0 ] . substring ( 5 ) ;
441
479
}
442
- file = __dirname + '/node_modules/iobroker.vis/www/' + f [ 0 ] ;
480
+ if ( f [ 0 ] . match ( / ^ l i b \/ c s s \/ t h e m e s \/ / ) ) {
481
+ file = __dirname + '/node_modules/iobroker.web/www/' + f [ 0 ] ;
482
+ } else {
483
+ file = __dirname + '/node_modules/iobroker.vis/www/' + f [ 0 ] ;
484
+ }
443
485
444
486
var info = getMime ( file ) ;
445
487
if ( fs . existsSync ( file ) ) {
0 commit comments