UNPKG

@leafage/server

Version:

The React Server Side Render Framework

54 lines (50 loc) 1.55 kB
/** * @leafage/server v1.3.2 * * Copyright (c) Leafage. * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ 'use strict'; var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js'); var createError = require('http-errors'); var routerPreset = function routerPreset(ctx) { ctx.app.use(/*#__PURE__*/function () { var _ref = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee(req, res, next) { var html, _t; return _rollupPluginBabelHelpers.regenerator().w(function (_context) { while (1) switch (_context.p = _context.n) { case 0: _context.p = 0; _context.n = 1; return ctx.renderer.renderRoute(req, res); case 1: html = _context.v; if (html) { _context.n = 2; break; } next(new createError.NotFound()); return _context.a(2); case 2: res.send(html); _context.n = 4; break; case 3: _context.p = 3; _t = _context.v; next(createError(_t.status || 500, _t)); case 4: return _context.a(2); } }, _callee, null, [[0, 3]]); })); return function (_x, _x2, _x3) { return _ref.apply(this, arguments); }; }()); }; exports.routerPreset = routerPreset;