Last active
July 20, 2018 20:38
-
-
Save caub/212458096f251d63138d2a76a089b53e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// render .js files as templates (they must be function taking options as arguments and outputting a valid HTML string) | |
app.engine('js', function (filePath, options, callback) { | |
if (process.env.NODE_ENV !== 'production') { | |
require.cache[filePath] = undefined; // invalidate require cache in dev | |
} | |
callback(null, require(filePath)(options)); // note: should wrap in a safeHtml in prod | |
}); | |
app.set('views', __dirname + '/views'); | |
app.set('view engine', 'js'); | |
// VS | |
app.engine('js', reactEngine); | |
function reactEngine(filePath, options, callback) { | |
const component = require(filePath); | |
const markup = renderToStaticMarkup(createElement(component, options)); | |
callback(null, markup); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment