Files
styled-components/packages/sandbox/server/appMiddleware.js
Bhargav Ponnapalli 4aa2fdbb3b Move to a mono-repo structure
wip

Add gitignore and edit rollup config

Update gitignore

Wip

WIP

Get rid of older json files and use js files to extend across pkgs later

Make test:native work again, thanks to @SimenB

No haste and get integration test to work

Update husky

Update package.json

Update travis and appveyor

Add lint script

Update sandbox

Update yarn version

Move eslint into sc package

Remove unnecessary files

Update lint-staged

Update CONTRIBUTING.md

Update version in lerna.json

Update contributing

Update scripts

Update contributing

Update contributing

Update contributing.md and publish script

Update contributing

v4.1.4-alpha.0

Update package json

Update lerna version

v4.1.4-alpha.0

v4.1.4-alpha.1

Independent version for sandbox and styled-components

Yarn instead of npm

Add readme to styled-components package to show up on npm

Publish

 - styled-components@4.1.4-alpha.2

Update prepublisOnly and contributing

Update gitignore

Publish

 - styled-components@4.1.4-alpha.3

Test without readme

Remove readme

Publish

 - styled-components@4.1.4-alpha.4

Copy readme prepublishOnly

Publish

 - styled-components@4.1.4-alpha.5
2019-01-18 21:04:15 +05:30

33 lines
919 B
JavaScript

const fs = require('fs');
const { send } = require('micro');
const { SANDBOX_PATHS, REPLACE_REGEX } = require('../util');
let cachedFile = null;
const asyncReadFile = (filePath, encoding) =>
new Promise((resolve, reject) => {
if (cachedFile !== null) {
resolve(cachedFile);
} else {
const callback = (err, data) => (err ? reject(err) : resolve((cachedFile = data)));
if (encoding) {
fs.readFile(filePath, encoding, callback);
} else {
fs.readFile(filePath, callback);
}
}
});
module.exports = async (req, res) => {
const template = await asyncReadFile(SANDBOX_PATHS.indexHtml, 'utf-8');
// eslint-disable-next-line global-require, import/no-dynamic-require
const { html: markup, css } = require(SANDBOX_PATHS.serverBuild);
const html = template.replace(REPLACE_REGEX.html, markup).replace(REPLACE_REGEX.css, css);
send(res, 200, html);
};