Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Soumyajit Pathak drenther

🏠
Working from home
View GitHub Profile
View db.json
{
"products" : [
{
"id" : 1,
"name" : "Crib One",
"desc" : "Cribs of the first kind. It's like a heavenly cloud to make your babies sleep sound.",
"price" : 45.99,
"thumbnail": "./assets/crib1.jpg",
"images": ["./assets/crib2.jpg", "./assets/crib3.jpg", "./assets/crib4.jpg", "./assets/crib5.jpg"]
},
@drenther
drenther / webpack.config.js
Created Jun 17, 2018
webpack config for react-basic-ssr
View webpack.config.js
const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const common = {
rules: [{ test: /\.(js)$/, use: 'babel-loader' }],
};
const clientConfig = {
entry: './src/client/index.js',
@drenther
drenther / .babelrc
Created Jun 17, 2018
.babelrc for react-ssr
View .babelrc
{
"presets": [
[
"env",
{
"targets": {
"browsers": ["last 2 versions"],
"node": "8.11.3"
}
}
@drenther
drenther / App.js
Created Jun 17, 2018
App.js for react-ssr
View App.js
import React, { Component } from 'react';
import { Switch, Navlink, Route } from 'react-router-dom';
import Navbar from './components/Navbar';
import NoMatch from './components/NoMatch';
import UniversalDataloader from './components/UniversalDataloader';
import routes from './routes';
class App extends Component {
@drenther
drenther / Home.js
Last active Jun 17, 2018
Presentational Components of react-ssr
View Home.js
import React from 'react';
import { Helmet } from 'react-helmet';
import { Link } from 'react-router-dom';
import Loading from './Loading';
const Home = ({ loading, data }) => (
<div className="home container">
<Helmet>
<title>FavMovies - Home</title>
@drenther
drenther / UniversalDataloader.js
Last active Jun 17, 2018
UniversalDataloader.js for react-ssr
View UniversalDataloader.js
import { Component } from 'react';
class UniversalDataloader extends Component {
constructor(props) {
super(props);
let data;
if (__isBrowser__ && window.__SERIALIZED_DATA__) {
data = window.__SERIALIZED_DATA__;
delete window.__SERIALIZED_DATA__;
@drenther
drenther / apiCalls.js
Created Jun 17, 2018
All the API requests for react-ssr
View apiCalls.js
import axios from 'axios';
const baseUri = 'http://localhost:3002';
export const fetchAllMovies = () =>
axios
.get(`${baseUri}/movies`)
.then(({ data }) => data)
.catch(e => {
console.log(e);
@drenther
drenther / routes.js
Created Jun 17, 2018
routes for react-ssr
View routes.js
import Home from './components/Home';
import Movie from './components/Movie';
import { fetchAllMovies, fetchMovieById } from './apiCalls';
const routes = [
{
path: '/',
exact: true,
C: Home,
@drenther
drenther / client.index.js
Created Jun 17, 2018
index.js for client of react-ssr
View client.index.js
import React from 'react';
import { hydrate } from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import App from '../shared/App';
hydrate(
<BrowserRouter>
<App />
</BrowserRouter>,
@drenther
drenther / server.index.js
Last active Jul 9, 2019
server/index.js for react-ssr
View server.index.js
import express from 'express';
import cors from 'cors';
import React from 'react';
import { Helmet } from 'react-helmet';
import { renderToString } from 'react-dom/server';
import { matchPath, StaticRouter } from 'react-router-dom';
import App from '../shared/App';
import routes from '../shared/routes';