@tdb/web
Version:
Common condiguration for serving a web-site and testing web-based UI components.
34 lines (29 loc) • 925 B
text/typescript
import { IDocumentGetInitialProps } from './types';
import * as bowser from 'bowser';
const glamor = require('glamor/server');
export { IDocumentGetInitialProps };
export { React, fastClick } from '../common';
export * from '../components';
/**
* Server renders the Glamor CSS.
*/
export function renderCss(args: IDocumentGetInitialProps) {
const page = args.renderPage();
const styles = glamor.renderStatic(() => page.html);
return { ...page, ...styles };
}
/**
* Retrieves browser information.
*/
export function browser(args: IDocumentGetInitialProps) {
const userAgent = args.req.headers['user-agent'] as string;
return bowser._detect(userAgent);
}
/**
* Determines if the app is running in dev mode.
*/
export function isDev(args: IDocumentGetInitialProps) {
const { req } = args;
const host = req.headers && req.headers.host && req.headers.host;
return host && host.startsWith('localhost');
}