/*
 Rookeries - Server-side renderer

 @copyright (c) Copyright 2013-2017 Dorian Pula
 @license AGPL v3
 @author Dorian Pula [dorian.pula@amber-penguin-software.ca]
 */

import {h} from 'preact';
import {render} from 'preact-render-to-string';
/** @jsx h */

import process from 'process';

import {StaticRouter} from 'react-router-dom';
import {Provider} from 'preact-redux';

import {RookeriesApp} from './containers/App';
import appStore from './store';

export function renderReactComponentsToString() {
  const url = process.argv[2];

  const context = {};
  return {
    bodyContent: render(h(
      <Provider store={ appStore }>
        <StaticRouter location={ url } context={ context }>
          <RookeriesApp />
        </StaticRouter>
      </Provider>
    ))
  };

}

let bodyResponse = renderReactComponentsToString();
console.log(bodyResponse.bodyContent);
