Initial commit

This commit is contained in:
Michael Jackson 2016-02-21 18:52:19 -08:00
commit eeb7b62dce
4 changed files with 139 additions and 0 deletions

11
package.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "npmcdn.com",
"version": "1.0.0",
"author": "Michael Jackson",
"license": "MIT",
"main": "server.js",
"dependencies": {
"cors": "^2.7.1",
"express": "^4.13.4"
}
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

110
public/index.html Normal file
View File

@ -0,0 +1,110 @@
<!DOCTYPE html>
<html>
<head>
<title>npmcdn</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
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;
}
</style>
</head>
<body>
<header>
<h1>npmcdn</h1>
</header>
<section id="wrapper">
<p>npmcdn is a CDN for packages that are published via <a href="https://www.npmjs.com/">npm</a>. Use it to quickly and easily load files using a simple URL like <code>https://npmcdn.com/package@version/path/to/file</code>.</p>
<p>A few examples:</p>
<ul>
<li><a href="/react@0.14.2/dist/react.min.js">https://npmcdn.com/react@0.14.2/dist/react.min.js</a></li>
<li><a href="/react-dom@0.14.2/dist/react-dom.min.js">https://npmcdn.com/react-dom@0.14.2/dist/react-dom.min.js</a></li>
<li><a href="/history@1.12.5/umd/History.min.js">https://npmcdn.com/history@1.12.5/umd/History.min.js</a></li>
<li><a href="/react-router@1.0.0/umd/ReactRouter.min.js">https://npmcdn.com/react-router@1.0.0/umd/ReactRouter.min.js</a></li>
</ul>
<p>You may also use a <a href="https://docs.npmjs.com/cli/dist-tag">tag</a> or <a href="https://docs.npmjs.com/misc/semver">version range</a> instead of a fixed version number, or omit the version/tag entirely to use the <code>latest</code> tag.</p>
<ul>
<li><a href="/react@^0.14/dist/react.min.js">https://npmcdn.com/react@^0.14/dist/react.min.js</a></li>
<li><a href="/react/dist/react.min.js">https://npmcdn.com/react/dist/react.min.js</a></li>
</ul>
<p>If you omit the file path, the <a href="https://docs.npmjs.com/files/package.json#main">main module</a> will be returned. This is especially useful for loading libaries that publish a UMD build as their main module.</p>
<ul>
<li><a href="/three">https://npmcdn.com/three</a></li>
<li><a href="/jquery">https://npmcdn.com/jquery</a></li>
<li><a href="/angular-formly">https://npmcdn.com/angular-formly</a></li>
</ul>
<p>If you use the special <code>/bower.zip</code> file path in a package that contains a <code>bower.json</code> file, a zip file will be created on the fly that Bower can use to install the package.</p>
<ul>
<li><a href="/react-swap/bower.zip">https://npmcdn.com/react-swap/bower.zip</a></li>
<li><a href="/react-collapse@1.6.3/bower.zip">https://npmcdn.com/react-collapse@1.6.3/bower.zip</a></li>
</ul>
<p><strong>Please note: <em>We do NOT recommend JavaScript libraries use Bower.</em></strong> 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 <a href="https://github.com/mjackson/npm-http-server#bower-support">here</a> for our rationale.</p>
<h3>Query Parameters</h3>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th width="80px">Name</th>
<th width="120px">Default Value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>main</code></td>
<td><code>main</code></td>
<td>The name of the field in <a href="https://docs.npmjs.com/files/package.json">package.json</a> to use as the main entry point when there is no file path in the URL. This value may be dot-separated to specify a nested field (e.g. <code>?main=config.browserMain</code>).</td>
</tr>
</tbody>
</table>
<h3>Suggested Workflow</h3>
<p>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 <a href="https://github.com/umdjs/umd">UMD</a> build in your npm package (not your repo, that's different!).</p>
<p>You can do this easily using the following setup:</p>
<ul>
<li>Add the <code>umd</code> (or <code>dist</code>) directory to your <code>.gitignore</code> file</li>
<li>Make sure you have a separate <code>.npmignore</code> file that <b>does not</b> list the <code>umd</code> directory. If you don't have an <code>.npmignore</code>, npm will attempt to ignore everything in your <code>.gitignore</code> when you <code>npm publish</code></li>
<li>Use a build script to generate your UMD build in the <code>umd</code> directory just before you publish. Your first thought might be to use npm's <code>prepublish</code> script for that, but I'd recommend you just use a separate build script, like <a href="https://github.com/mjackson/expect/blob/master/scripts/release.sh">this one</a> because prepublish <a href="https://github.com/npm/npm/issues/3059">can also run when you don't expect it to</a></li>
<li>That's it! Now when you <code>npm publish</code> you'll have a version available on npmcdn as well</li>
</ul>
<h3>Feedback</h3>
<p>If you think this is useful, I'd love to hear from you. Please reach out to <a href="https://twitter.com/mjackson">@mjackson</a> with any questions/concerns.</p>
<p>Also, please feel free to examine the source on <a href="https://github.com/mjackson/npm-http-server">GitHub</a>.</p>
</section>
</body>
</html>

18
server.js Normal file
View File

@ -0,0 +1,18 @@
var port = process.env.PORT || 5000
var express = require('express')
var createRequestHandler = require('npm-http-server').createRequestHandler
var cors = require('cors')
var app = express()
app.disable('x-powered-by')
app.use(cors())
app.use(express.static('public', { maxAge: 60000 }))
app.use(
createRequestHandler()
)
app.listen(port, function () {
console.log('Server started on port ' + port + '. Ctrl+C to quit')
})