Skip to content

Instantly share code, notes, and snippets.

@mike-casas
Created June 9, 2016 02:08
Show Gist options
  • Save mike-casas/a8baaf78ecde920d6e6ca46a4ec66024 to your computer and use it in GitHub Desktop.
Save mike-casas/a8baaf78ecde920d6e6ca46a4ec66024 to your computer and use it in GitHub Desktop.
import React from 'react';
import Header from '../../components/Header';
import Footer from '../../components/Footer';
import Spinner from '../../components/Spinner';
function App(props) {
return (
<div id="application">
<Header />
<div className="site-content">{props.children}</div>
<Footer />
<Spinner />
</div>
);
}
App.propTypes = {
children: React.PropTypes.node
};
export default App;
import 'babel-polyfill';
import React from 'react';
import { render } from 'react-dom';
import { match, Router, browserHistory } from 'react-router';
import routes from './routes';
import { main as mainLock } from './core/locks';
import ee from './core/eventemitter';
const { pathname, search, hash } = window.location;
const location = `${pathname}${search}${hash}`;
match({ routes, location }, () => {
render(<Router routes={routes} history={browserHistory} />, document.getElementById('app'));
});
mainLock.lock.getClient().getSSOData(false, (err, data) => {
if (err) return;
ee.emit('logged', data);
});
import React from 'react';
export default class Home extends React.Component {
render() {
return (
<div>Home aa</div>
);
}
}
import { App, Home, NotFound, Preview } from './containers';
const routes = [{
path: '/resources',
component: App,
indexRoute: { component: Home },
childRoutes: [{
path: ':categoryHash/:articleHash/preview',
component: Preview
}]
}, {
path: '/*',
component: NotFound
}];
export default routes;
import 'babel-polyfill';
import 'source-map-support/register';
import path from 'path';
import express from 'express';
import React from 'react';
import { renderToString } from 'react-dom/server';
import { match, RouterContext } from 'react-router';
import { port } from './config';
import routes from './routes';
import template from './views/index.jade';
const http = require('http');
const server = express();
const app = http.createServer(server);
const api = require('../api_server/api');
const webpack = require('webpack');
const webpackConfig = require('../frontendConfig');
const compiler = webpack(webpackConfig);
server.use(require('webpack-dev-middleware')(compiler, {
stats: {
colors: true,
hash: false,
timings: true,
chunks: false,
chunkModules: false,
modules: false
},
publicPath: webpackConfig.output.publicPath
}));
// Step 3: Attach the hot middleware to the compiler & the server
server.use(require('webpack-hot-middleware')(compiler, {
log: console.log, path: '/__webpack_hmr', heartbeat: 10 * 1000
}));
function matchRouter(req, res) {
match({ routes, location: req.url }, (error, redirectLocation, renderProps) => {
if (error) {
return res.status(500).send(error.message);
} else if (redirectLocation) {
return res.redirect(302, redirectLocation.pathname + redirectLocation.search);
}
const isNotFound = renderProps.routes.filter(route => route.name === '404')[0];
const status = isNotFound ? 404 : 200;
const body = renderToString(<RouterContext {...renderProps} />);
return res.status(status).send(template({
content: body
}));
});
}
server.use(express.static(path.join(__dirname, 'public')));
server.get('/', (req, res) => {
res.redirect('/resources');
});
server.get('/resources*', (req, res, next) => {
matchRouter(req, res);
next();
});
server.use('/api', api);
server.listen(port, '0.0.0.0', function onStart(err) {
if (err) {
console.log(err);
}
console.info('==> 🌎 Listening on port %s. Open up http://0.0.0.0:%s/ in your browser.', port, port);
});
doctype html
html(class='no-js', lang='en')
head
meta(charset='utf-8')
title Showcase - Auth0.
link(rel='shortcut icon', href='https://cdn.auth0.com/styleguide/1.0.0/img/favicon.png')
link(href='https://cdn.auth0.com/styleguide/latest/index.css', rel='stylesheet')
script.
document.documentElement.className = document.documentElement.className.replace('no-js', 'js');
link(href=css, rel='stylesheet')
body(class='body--no-scroll')
div#app!=body
script(src='https://apis.google.com/js/client.js')
script(src=js)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment