Skip to content

Instantly share code, notes, and snippets.

.wrapper {
background: red;
}
import React from 'react';
import { render } from 'react-dom';
import App from './components/App';
render(<App />, document.getElementById('root'));
import express from 'express';
import webpack from 'webpack';
const render = require('../dist/assets/SSR');
const app = express();
app.get('/', render.default);
const port = 3000;
app.listen(port);
import React from 'react';
import { renderToString } from 'react-dom/server';
import template from './template';
import App from './components/App';
export default function render(req, res) {
const appString = renderToString(<App />);
res.send(template({
body: appString,
title: 'FROM THE SERVER',
const path = require('path');
const nodeExternals = require('webpack-node-externals');
module.exports = {
name: 'SSR',
entry: './app/SSR.js',
output: {
path: path.join(__dirname, '.', 'dist', 'assets'),
filename: 'SSR.js',
libraryTarget: 'commonjs2',
import express from 'express';
import React from 'react';
import { renderToString } from 'react-dom/server';
import App from '../app/components/App';
import template from '../app/template';
const app = express();
app.get('/', (req, res) => {
const appString = renderToString(<App />);
export default ({ body, title }) => {
return `
<!DOCTYPE html>
<html>
<head>
<title>${title}</title>
</head>
<body>
<div id="root">${body}</div>
import React, { Component } from 'react';
export default class App extends Component {
render() {
return (
<div>
Hello world!
</div>
);
}
{
"presets": [
"es2015",
"react",
"stage-0"
]
}
@hyperh
hyperh / set-token.js
Last active May 20, 2016 06:37
Setting device-specific push notification token
const SET_PUSH_TOKEN = 'notifications.set.pushToken';
Meteor.methods({
'notifications.set.pushToken'({token, os}) {
check(arguments[0], {
token: String,
os: String,
});
const userId = this.userId;
if (!userId) {