UNPKG

react-cosmos

Version:

CLI for running React Cosmos inside webpack-powered apps

51 lines (38 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createApp = createApp; var _express = _interopRequireDefault(require("express")); var _resolveFrom = _interopRequireDefault(require("resolve-from")); var _playgroundHtml = require("../shared/playgroundHtml"); var _static = require("../shared/static"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function createApp(platformType, cosmosConfig, pluginConfigs) { var app = (0, _express.default)(); var playgroundHtml = (0, _playgroundHtml.getDevPlaygroundHtml)(platformType, cosmosConfig, pluginConfigs); app.get('/', function (req, res) { res.send(playgroundHtml); }); app.get('/_plugin/:scriptPath', function (req, res) { var scriptPath = req.params.scriptPath; if (!scriptPath) { res.sendStatus(404); return; } // TODO: Restrict which scripts can be opened based on plugin configs var cleanPath = "./".concat(decodeURIComponent(scriptPath)); var absolutePath = _resolveFrom.default.silent(cosmosConfig.rootDir, cleanPath); if (!absolutePath) { res.sendStatus(404); return; } res.sendFile(absolutePath); }); app.get('/_playground.js', function (req, res) { res.sendFile(require.resolve('react-cosmos-playground2/dist')); }); app.get('/_cosmos.ico', function (req, res) { res.sendFile((0, _static.getStaticPath)('favicon.ico')); }); return app; }