HTTP/RPC Server of the-framework
npm install @the-/server@the-/server
==========
[![npm Version][bd_npm_shield_url]][bd_npm_url]
[bd_repo_url]: https://github.com/the-labo/the
[bd_npm_url]: http://www.npmjs.org/package/@the-/server
[bd_npm_shield_url]: http://img.shields.io/npm/v/@the-/server.svg?style=flat
HTTP/RPC Server of the-framework
Installation
-----
``bash`
$ npm install @the-/server --save
Usage
---------
`javascript
'use strict'
const React = require('react')
const theServer = require('@the-/server')
const { createElement: c } = React
;(async () => {
// Define RPC Controller Class
const FruitShopCtrl = ({ session }) => ({
async addToCart(name, amount = 1) {
const { cart = {} } = session
cart[name] = (cart[name] || 0) + amount
session.cart = cart
},
async buy() {
const { cart = {} } = session
console.log(cart)
/ ... /
},
})
// Define real time event handling stream
const CountdownStream = ({ params }) => ({
async *provide() {
let count = params.count || 100
while (count > 0) {
yield { count }
count--
}
},
})
const server = theServer({
// Register controller with name
// Controller instance will be created for each method call
controllers: {
fruitShop: FruitShopCtrl,
},
/**
* View renderer
@param {} children
*/
html: ({ children }) => c('html', {}, c('body', {}, children)),
/**
* Redis config
*/
redis: { db: 1, host: '127.0.0.1', port: '6379' },
/**
* Directory path to serve static files
*/
static: 'public',
streams: {
countdown: CountdownStream,
},
})
await server.listen(3000)
})().catch((e) => console.error(e))
``
- InfoFlusher~infoFlusher
- .flushInfo()
- global
- IOEvents()
- module:@the-/server
- .adapters
- .assert
- .buildInEndpoints
- .connectors
- .constants
- .create(args)
- .default()
- .helpers
- .stores
- .TheServer
- module:@the-/server.adapters
- .redisAdapter(io,options=)
- module:@the-/server.assert
- .assertMethods(Class,reservedNames)
- module:@the-/server.connectors
- .IOConnector()
- module:@the-/server.constants
- .DefaultValues
- module:@the-/server.helpers
- .asStrictSession(session)
- .callbacksProxy(options=)
- .ClientAccess(config)
- .ctxInjector(creators)
- .InfoFlusher(filename,getter)
- .langDetector(locales,options)
- .MetricsCounter()
- .queryFromUrl(urlString)
- .RPCKeeper(Class)
- .serverRendering(Component,options)
- .serverRendering(Html,options=)
- .streamPool()
- .toControllerDriverFactory(ControllerFactory,options=)
- .toLowerKeys(values=)
- ~StreamDriverPool()
- module:@the-/server.helpers.ClientAccess
- ~clientAccess
- module:@the-/server.helpers.InfoFlusher
- ~infoFlusher
- module:@the-/server.helpers.metricsMix
- ~metricsCounter
- module:@the-/server.helpers.RPCKeeper
- ~rpcKeeper
- module:@the-/server.stores
- .ConnectionStore
- .SessionStore
- .Store
- module:@the-/server.streaming
- .toStreamDriverFactory(StreamFactory,options=)
- SessionAccess~sessionAccess
- .reload()
- .save(options)
- Store
- #cleanup()
- #del(id)
- #delAll()
- #get(id)
- #has(id)
- #ids()
- #set(id,data)
- TheServer
- #close(args)
- #destroyAllSessions()
- #info()
- #listen(port)
See API Guide for more detail
License
-------
This software is released under the MIT License.
Links
------
+ [THE Labo][the_labo_url]
[the_labo_url]: https://github.com/the-labo