lado
---
Last updated 3 years ago by conarwelsh .
ISC · Original npm · Tarball · package.json
$ cnpm install lado 
SYNC missed versions from official npm registry.

lado


CircleCI Codacy Badge Code Climate Test Coverage Issue Count

A framework to declaratively create applications using any combination of the following:

  • express
  • graphql
  • apollo
  • react

Documentation is mostly non-existant at the moment, however the code is well commented and easy to follow.


Recommended Folder Structure

\
	\app
		\actions
		\components
		\containers
		\pages
		\reducers
		\styles
		client.js
		index.js
	\migrations
	\public
	\server
		\config
			app.js
			auth.js
			database.js
			graphql.js
			static.js
			views.js
		\controllers
		\models
		\repositories
		\schema
			\mocks
			\resolvers
			index.js
		\views
		index.js

Server

server/index.js

import path from 'path'
import lado from 'lado'

//have it load all files in the config folder
lado.configure(path.join(__dirname, 'config'))

//graphql middleware
lado.use('/graphql', lado.graphMiddleware())

//lado exposes all express methods, so you can basically
//just treat lado as an express instance
lado.get('/admin*', (req, res, next) => {
	res.render('index', {
		appScript: '/js/admin.js'
	})
})

lado.get('/*', (req, res, next) => {
	res.render('index', {
		appScript: '/js/app.js',
	})
})

lado.listen()

app/index.js

import React from 'react'
import { render } from 'react-dom'
import { ApolloProvider } from 'react-apollo'
import { Router, Route, IndexRoute, browserHistory } from 'react-router'
import { syncHistoryWithStore } from 'react-router-redux'

import {
  client,
  store,
} from './client'

const history = syncHistoryWithStore(browserHistory, store)

import AppContainer from './containers/AppContainer'
import Blog from './pages/Blog'
import Post from './pages/Post'

render(
  <ApolloProvider store={store} client={client}>
    <Router history={history}>
  	  <Route path="/" component={AppContainer}>
  	    <IndexRoute component={Blog} />
  	    <Route path="post/:slug" component={Post} />
  	  </Route>
  	</Router>
  </ApolloProvider>,
  document.getElementById('root')
)

app/client.js

import ApolloClient, { createNetworkInterface } from 'apollo-client';
import { createStore, combineReducers, applyMiddleware } from 'redux'
import ReduxThunk from 'redux-thunk'
import { routerReducer } from 'react-router-redux'
import { auth } from './reducers'

const networkInterface = createNetworkInterface('/graphql')

networkInterface.use([{
  applyMiddleware(req, next) {
    if ( ! req.options.headers) {
      req.options.headers = {};  // Create the header object if needed.
    }
    
    const TOKEN = typeof localStorage !== 'undefined'
      &&  localStorage.getItem('token')

    req.options.headers.Authorization = 'Bearer ' + TOKEN;
    next();
  }
}]);

const client = new ApolloClient({
	networkInterface,
	reduxRootKey: 'myStoreKey',
});

const store = createStore(
  combineReducers({
    auth,
    routing: routerReducer,
    myStoreKey: client.reducer(),
  }),
  applyMiddleware(client.middleware(), ReduxThunk.withExtraArgument(client)),
)

export {
	client,
	store,
}

export default client

Current Tags

  • 0.3.0                                ...           latest (3 years ago)

12 Versions

  • 0.3.0                                ...           3 years ago
  • 0.2.8                                ...           3 years ago
  • 0.2.7                                ...           3 years ago
  • 0.2.6                                ...           3 years ago
  • 0.2.5                                ...           3 years ago
  • 0.2.4                                ...           3 years ago
  • 0.2.3                                ...           3 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 8
Dependencies (45)
Dev Dependencies (9)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |