# all files / keystone/admin/server/app/ createStaticRouter.js

19.23% Statements 5/26
100% Branches 0/0
0% Functions 0/2
19.23% Lines 5/26

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64

    1×
    1×
    1×
    1×

    1×

     /**
     * Returns an Express Router with bindings for the Admin UI static resources,
     * i.e files, less and browserified scripts.
     *
     * Should be included before other middleware (e.g. session management,
     * logging, etc) for reduced overhead.
     */

    var browserify = require('../middleware/browserify');
    var express = require('express');
    var less = require('less-middleware');
    var path = require('path');

    module.exports = function createStaticRouter (keystone) {
    	var router = express.Router();

    	/* Prepare browserify bundles */
    	var bundles = {
    		fields: browserify('fields.js', 'FieldTypes'),
    		signin: browserify('views/signin.js'),
    		home: browserify('views/home.js'),
    		item: browserify('views/item.js'),
    		list: browserify('views/list.js'),
    	};

    	// prebuild static resources on the next tick
    	// improves first-request performance
    	process.nextTick(function () {
    		bundles.fields.build();
    		bundles.signin.build();
    		bundles.home.build();
    		bundles.item.build();
    		bundles.list.build();
    	});

    	/* Prepare LESS options */
    	var elementalPath = path.join(path.dirname(require.resolve('elemental')), '..');
    	var reactSelectPath = path.join(path.dirname(require.resolve('react-select')), '..');
    	var customStylesPath = keystone.getPath('adminui custom styles', 'customStyles/index.less');

    	var lessOptions = {
    		render: {
    			modifyVars: {
    				elementalPath: JSON.stringify(elementalPath),
    				reactSelectPath: JSON.stringify(reactSelectPath),
    				customStylesPath: JSON.stringify(customStylesPath),
    				adminPath: JSON.stringify(keystone.get('admin path')),
    			},
    		},
    	};

    	/* Configure router */
    	router.use('/styles', less(path.resolve(__dirname + '/../../public/styles'), lessOptions));
    	router.use('/styles/fonts', express.static(path.resolve(__dirname + '/../../public/js/lib/tinymce/skins/keystone/fonts')));
    	router.get('/js/fields.js', bundles.fields.serve);
    	router.get('/js/signin.js', bundles.signin.serve);
    	router.get('/js/home.js', bundles.home.serve);
    	router.get('/js/item.js', bundles.item.serve);
    	router.get('/js/list.js', bundles.list.serve);
    	router.use(express.static(path.resolve(__dirname + '/../../public')));

    	return router;
    };