Code Monkey home page Code Monkey logo

judo-heroes's Introduction

judo-heroes

A simple application built to showcase Universal JavaScript with Node.js and React.

😱 NEW VERSION AVAILABLE

A new version of the codebase is available in a dedicated repository: https://github.com/lmammino/judo-heroes-2

The new version includes the following changes and improvements:

  • Updated to Webpack 2, React 15.4, React Router 4 and Express 5
  • Using pure components where possible
  • Better structure of componenents
  • Top down data passing

Be sure to ⬇️ checkout and ⭐️ star the new repository if you are interested in fresher code.

The tutorial

This application was created to support a "Universal Javascript" (aka Isomorphic) tutorial published on Scotch.io:

React on the Server for Beginners: Build a Universal React and Node App

React on the Server for Beginners: Build a Universal React and Node App

Want to know more about Node.js, React and Universal Javascript?

If you want to know more about Universal Javascript and improve your application even more (e.g. by adding Universal Data Retrival using REST APIs) I definitely recommend to read the chapter Universal JavaScript for Web Applications on my book Node.js Design Patterns Second Edition (Packt):

Node.js Design Patterns Second Edition by Mario Casciaro and Luciano Mammino

Contributing

Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue or by sending a pull request.

License

Licensed under MIT License. © Luciano Mammino.

judo-heroes's People

Contributors

lmammino avatar mtrabelsi avatar rlyders avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

judo-heroes's Issues

How to get this working with SCSS?

Thanks for the great tutorial and sample app. I've been working on a project that uses webpack's css-loader and style-loader. Things work fine for the development server, however, when running npm run start it looks like Babel doesn't know what to do about importing the SCSS or CSS files. This isn't a problem with your application, but I'm wondering if you have any ideas.

So I have a Layout component in ~/source/components/layout/layout.jsx:

import React from 'react';
import styles from './layout.scss';

export default class Layout extends React.Component {
  render() {
    return (
      <div className={styles.layout}>
        <h1>You Got the Layout!</h1>
        <main className={styles.main}>{this.props.children}</main>
      </div>
    );
  }
}

Notice it is importing the SCSS from ./layout.scss. However, when I run start I get the following:

$ npm run start
> NODE_ENV=production node_modules/.bin/babel-node source/server.js

~/node_modules/babel-core/lib/transformation/file/index.js:600
      throw err;
      ^

SyntaxError: ~/source/components/layout/layout.scss: Unexpected token (1:0)
> 1 | .layout {
    | ^
  2 |   background-color:dodgerblue;
  3 |   padding: 1em;
  4 |   color: white;
    at Parser.pp$5.raise (~/node_modules/babylon/lib/index.js:4246:13)
    at Parser.pp.unexpected (~/node_modules/babylon/lib/index.js:1627:8)
    at Parser.pp$3.parseExprAtom (~/node_modules/babylon/lib/index.js:3586:12)
    at Parser.parseExprAtom (~node_modules/babylon/lib/index.js:6402:22)
    at Parser.pp$3.parseExprSubscripts (~/node_modules/babylon/lib/index.js:3331:19)
    at Parser.pp$3.parseMaybeUnary (~/node_modules/babylon/lib/index.js:3311:19)
    at Parser.pp$3.parseExprOps (~/node_modules/babylon/lib/index.js:3241:19)
    at Parser.pp$3.parseMaybeConditional (~/node_modules/babylon/lib/index.js:3218:19)
    at Parser.pp$3.parseMaybeAssign (~/node_modules/babylon/lib/index.js:3181:19)
    at Parser.parseMaybeAssign (~/node_modules/babylon/lib/index.js:5694:20)

I've seen the ignore option for Babel, but couldn't get it to work, and it looks like there are some issues with it anyway.

I've also seen webpack/webpack#1754.

In other projects I've seen that webpack is run first, but I'm not getting how to do this with your express setup.

If anyone has any ideas, please let me know. Thanks.

React.createElement: type is invalid

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check your code at routes.js:10.

This is my routes.js file

import React from 'react'
import { Route, IndexRoute } from 'react-router'
import Layout from './components/Layout';
import IndexPage from './components/IndexPage';
import AthletePage from './components/AthletePage';
import NotFoundPage from './components/NotFoundPage';

const routes = (
  <Route path="/" component={Layout}>
    <IndexRoute component={IndexPage}/>
    <Route path="athlete/:id" component={AthletePage}/>
    <Route path="*" component={NotFoundPage}/>
  </Route>
);

export default routes;

Row 10 is:

<IndexRoute component={IndexPage}/>

And this is IndePage component source

import React, { Component } from 'react';
import AthletePreview from './AthletePreview';
import athletes from '../data/athletes';

export default class IndexPage extends Component {
  render() {
    return (
      <div className="home">
        <div className="athletes-selector">
          {athletes.map(athleteData => <AthletePreview key={athleteData.id} {...athleteData} />)}
        </div>
      </div>
    );
  }
}

really, I've no idea of what am I doing wrong.

TypeError: window.addEventListener is not a function

I am getting this error after using new functionality in same library:

TypeError: window.addEventListener is not a function

There was another error: window is not defined which I fixed using
if (typeof window === 'undefined') {
global.window = {};
}

Can you help me out?

"NODE_ENV=production node_modules/.bin/webpack -p" produce no bundle.js file

I am working through your amazing article building every js file step by step and finally i have reached this line: "NODE_ENV=production node_modules/.bin/webpack -p".
I have added npm script like this:
"scripts": {
"build": "NODE_ENV=production node_modules/.bin/webpack -p"
}
and get returned an error. And smart guys whispered me that as soon as i am on windows i should prepend script with "set" so i changed it to:
"build": "set NODE_ENV=production node_modules/.bin/webpack -p"

Now i got no errors but no bundle.js file is produced. Simply nothing.
Please help me to figure this out.

Data on Client or Server?

Hello,

Thank you for taking the time to read this.

I'm just curious,

Does the code for judo-heroes/src/data/athletes.js exist on the client or on the server?

If I replace those codes with data gotten from MongoDB, would my mongo codes be exposed on the client side?

Also, since this app is isomorphic/universal, I can simply use mongoDB from the client side? Or must I still call the REST endpoints from the frontend? (It's not recommended to use JQuery's AJAX anymore with React right?)

Hope to hear from you soon!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.