ryuu-server-beta

0.1.0 • Public • Published

Ryuu Server

Easy, low profile, koa server/proxy to allow for data calls to Domo. Uses your current domo login info for authentication. domo devs backend with your own front end bundler.

  • Install
npm install ryuu-server-beta --save-dev
  • For webpack builds Webpack 2+, node 6.10.3+

only use this if you know how webpack works and have configured a webpack server before

Install koa-webpack, which enables the koa server to mingle with the express server.

 npm install koa-webpack --save-dev

Adjust your server initialization file to look like the following:

// whichever file you normally initialize your webpack server
const webpack = require('webpack');

const ryuuServer = require('ryuu-server-beta');

// webpackConfig here is being imported 
const compiler = webpack(webpackConfig);

const RyuuDevServer = require('koa-webpack');

the rest of the server file can follow the pattern from below, but feel free to change some values if you know it won't affect koa-webpack:

const path = require('path');
const portfinder = require('portfinder');
//you could import these configs below like I have done in the beginning of  
//this file, showing here to easier see what they should resemble

const devConfig = {
    contentBase: path.join(process.cwd(), 'dist'),
    publicPath: '/',
    clientLogLevel: 'error',
    noInfo: false, // set to false if you want to see build info
    stats: {
        colors: true
    },
};
// if you dont care about HMR, do not worry about adding a hot cofnig
const hotConfig = {
    log: console.log,
    path: '/__webpack_hmr',
};
//you can put it on any port you want, just make sure you change your entry property in your webpack config to reflect the port number
portfinder.basePort = 3000;
//notice a slightly different schema for this dev server compared to a       //regular webpack-dev-server
const middleware = RyuuDevServer({ compiler, dev: devConfig, hot: hotConfig });
//here we pass the koa-webpack compiler to the ryuu server  
ryuuServer.use(middleware);
//ryuu-server-beta has a single custom method, .sessionCheck(), that ensures //you are properly authenticated to a domo instance. It returns a promise    //that you can wait for to eventually spin up the ryuuServer through the     //native .listen() method.

ryuuServer.sessionCheck().then(() => {
    portfinder.getPort({
        host: '0.0.0.0'
    }, (err, port) => {
        ryuuServer.listen(port || 3000, '0.0.0.0', () => {
            console.log('Listening on http://0.0.0.0:' + port + '/');
        });
    });
});

If you want hot reloading, add 'webpack-hot-middleware/client?http://0.0.0.0:3000/__webpack_hmr&reload=true' into the entry array. This connects to the server to receive notifications when the bundle rebuilds and then updates your client bundle accordingly.

Be sure to be domo logind to an instance. Then in your /src dir, make sure to have a valid manifest.json to retrieve datasource and alias information from. If you dont have a /src folder, and store your manifest.json elsewhere, change the ryuuServer.options.manifestDir prior to your .sessionCheck(), where the manifest.json is actually retrieved.

Now, run npm start, go to the url it logs, and you should have working /data/v1/ calls routing through your webpack build.

Other build tools

If you have are using a build tool other than webpack, configuration should be fairly simple. Webpack is definitely the most complex for integration. Please drop an issue if you need help implementating another.

Requests

This is a work in progress. Your feedback is needed to know what would be a desired addition, feature, or change. Please log an issue or better yet, submit a PR.

Readme

Keywords

none

Package Sidebar

Install

npm i ryuu-server-beta

Weekly Downloads

16

Version

0.1.0

License

none

Last publish

Collaborators

  • bmoss
  • jgalb