diff --git a/modules/ServerUtils.js b/modules/ServerUtils.js index 38ff027..f7493d8 100644 --- a/modules/ServerUtils.js +++ b/modules/ServerUtils.js @@ -1,18 +1,30 @@ +import path from 'path' import cors from 'cors' import express from 'express' +import ExpressReactViews from 'express-react-views' import { createRequestHandler } from 'npm-http-server' import { logStats } from './StatsUtils' +const serveHomePage = (req, res) => + res.render('HomePage') + export const createServer = (options = {}) => { const app = express() app.disable('x-powered-by') + app.set('view engine', 'js') + app.set('views', path.resolve(__dirname, 'components')) + app.engine('js', ExpressReactViews.createEngine({ + transformViews: false + })) + app.use(cors()) app.use(express.static('public', { maxAge: 60000 })) if (options.redisURL) app.use(logStats(options.redisURL)) + app.get('/', serveHomePage) app.use(createRequestHandler(options)) return app diff --git a/modules/components/HomePage.js b/modules/components/HomePage.js new file mode 100644 index 0000000..f899fa7 --- /dev/null +++ b/modules/components/HomePage.js @@ -0,0 +1,128 @@ +import React from 'react' + +const styles = ` +body { + font: 14px Helvetica, sans-serif; + line-height: 1.5; + padding: 5px 20px; +} +@media all and (min-width: 660px) { + body { + padding: 50px 20px; + } +} +header, #wrapper { + max-width: 600px; + margin: 0 auto; +} +header { + text-align: center; +} +code { + background: #eee; +} +table { + border-color: black; + border-style: solid; + border-width: 0 0 1px 1px; +} +table th, table td { + text-align: left; + vertical-align: top; + padding: 5px 7px; + border-color: black; + border-style: solid; + border-width: 1px 1px 0 0; +} +` + +const HomePage = React.createClass({ + render() { + return ( + + + npmcdn + + - - -
-

npmcdn

-
-
-

npmcdn is a CDN for packages that are published via npm. Use it to quickly and easily load files using a simple URL like https://npmcdn.com/package@version/path/to/file.

-

A few examples:

- - -

You may also use a tag or version range instead of a fixed version number, or omit the version/tag entirely to use the latest tag.

- - -

If you omit the file path, the main module will be served. This is especially useful for loading libaries that publish a UMD build as their main module.

- - -

Append a / at the end of a URL to view a listing of all the files in a package.

- - -

You may use the special /bower.zip file path in packages that contain a bower.json file to dynamically generate a zip file that Bower can use to install the package.

- - -

Please note: We do NOT recommend JavaScript libraries use Bower. Bower places additional burdens on JavaScript package authors for little to no gain. npmcdn is intended to make it easier to publish code, not harder, so Bower support will be removed in January 2017. Please move to npm for installing packages and stop using Bower before that time. See here for our rationale.

- -

Query Parameters

- - - - - - - - - - - - - - - -
NameDefault ValueDescription
mainmainThe name of the field in package.json to use as the main entry point when there is no file path in the URL (e.g. ?main=browser).
- -

Suggested Workflow

-

For npm package authors, npmcdn relieves the burden of publishing your code to a CDN in addition to the npm registry. All you need to do is include your UMD build in your npm package (not your repo, that's different!).

-

You can do this easily using the following setup:

- -

That's it! Now when you npm publish you'll have a version available on npmcdn as well.

- -

Feedback

-

If you think this is useful, I'd love to hear from you. Please reach out to @mjackson with any questions/concerns.

-

Also, please feel free to examine the source on GitHub.

-
- -