Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/react-server / dist / middleware / fsMiddleware.js
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * @file this whole file is already done?
 */
var bs_1 = require("@skava/bs");
var deps_1 = require("../deps");
var expireSettings = {
    maxAge: process.env.BROWSER_MAX_CACHE_AGE,
    index: false,
};
function fromExtToContentType(ext) {
    switch (true) {
        case ext.includes('html'):
            return 'text/html';
        case ext.includes('json') || ext.includes('.map'):
            return 'application/json';
        default:
        case ext.includes('js'):
            return 'text/javascript';
    }
}
function toResolvedFileMeta(resolvedPathname) {
    return [
        resolvedPathname,
        {
            headers: {
                'Content-Type': fromExtToContentType(resolvedPathname),
            },
        },
    ];
}
/**
 * @todo resolve to root same as express static
 * @see https://medium.com/@rajaraodv/webpack-hot-module-replacement-hmr-e756a726a07
 * @see http://code.fitness/post/2016/02/webpack-public-path-and-hot-reload.html
 */
// @lint - console logs take more statements
// eslint-disable-next-line
function fsMiddleware(req, res, next) {
    var pathname = req.pathname || req.originalUrl;
    if (process.env.NODE_ENV === 'production') {
        console.log('ignoring route, on deployment');
        next();
        return;
    }
    if (pathname === undefined) {
        console.log('[react-server] unknown request', deps_1.fromReqResToDebug(req));
        next();
    }
    else if (pathname.includes('client') && pathname.includes('js')) {
        var pathnameFixed = pathname.replace('client', 'client/');
        var resolvedPathname = bs_1.resolveToRoot('dist/dist/bundled' + pathnameFixed);
        console.log('[react-server] client request ', resolvedPathname);
        res.sendFile.apply(res, toResolvedFileMeta(resolvedPathname));
    }
    else if (pathname.includes('hmr') && pathname.includes('js')) {
        var resolvedPathname = bs_1.resolveToRoot('dist/dist/bundled' + pathname);
        console.log('[react-server] HMR_MIDDLEWARE ', resolvedPathname);
        res.sendFile.apply(res, toResolvedFileMeta(resolvedPathname));
    }
    else {
        console.log('[react-server] unknown request ', deps_1.fromReqResToDebug(req));
        next();
    }
}
exports.fsMiddleware = fsMiddleware;
//# sourceMappingURL=fsMiddleware.js.map