Commit 3782856c authored by Robert Knight's avatar Robert Knight

Update the package server's URL structure to mirror cdn.hypothes.is

 - /hypothesis and /hypothesis@X.Y.Z serve the boot script

 - /hypothesis/X.Y.Z/ serves the files for a given version of the
   package
parent 751a0503
...@@ -271,7 +271,7 @@ function generateBootScript(manifest) { ...@@ -271,7 +271,7 @@ function generateBootScript(manifest) {
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
defaultAssetRoot = `https://cdn.hypothes.is/hypothesis/${version}/`; defaultAssetRoot = `https://cdn.hypothes.is/hypothesis/${version}/`;
} else { } else {
defaultAssetRoot = `http://${packageServerHostname()}:3001/hypothesis@${version}/`; defaultAssetRoot = `http://${packageServerHostname()}:3001/hypothesis/${version}/`;
} }
if (isFirstBuild) { if (isFirstBuild) {
......
...@@ -10,10 +10,8 @@ var { version } = require('../../package.json'); ...@@ -10,10 +10,8 @@ var { version } = require('../../package.json');
/** /**
* An express server which serves the contents of the package. * An express server which serves the contents of the package.
* *
* The server behaves similarly to npm CDNs, such as unpkg.com. The * The server mirrors the URL structure of cdn.hypothes.is, an S3-backed domain
* '/hypothesis@VERSION' route returns the contents of the package's entry * which serves the client's assets in production.
* point. Other routes return the contents of the specified file within the
* package.
* *
* When developing the client, the Hypothesis service should be configured to * When developing the client, the Hypothesis service should be configured to
* use the URL of this service as the client URL, so that the boot script is * use the URL of this service as the client URL, so that the boot script is
...@@ -23,23 +21,17 @@ var { version } = require('../../package.json'); ...@@ -23,23 +21,17 @@ var { version } = require('../../package.json');
function servePackage(port, hostname) { function servePackage(port, hostname) {
var app = express(); var app = express();
// Set up redirects which mirror unpkg's behavior var serveBootScript = function (req, res) {
app.get('/hypothesis', function (req, res) {
res.redirect(302, `/hypothesis@${version}`);
});
app.get('/hypothesis/*', function (req, res) {
var path = req.path.replace('/hypothesis/', '');
res.redirect(302, `/hypothesis@${version}/${path}`);
});
app.get(`/hypothesis@${version}`, function (req, res) {
var entryPath = require.resolve('../..'); var entryPath = require.resolve('../..');
var entryScript = readFileSync(entryPath).toString('utf-8'); var entryScript = readFileSync(entryPath).toString('utf-8');
res.send(entryScript); res.send(entryScript);
}); };
app.use(`/hypothesis@${version}/`, express.static('.')); // Set up URLs which serve the boot script and package content, mirroring
// cdn.hypothes.is' structure.
app.get('/hypothesis', serveBootScript);
app.get(`/hypothesis/${version}`, serveBootScript);
app.use(`/hypothesis/${version}/`, express.static('.'));
app.listen(port, function () { app.listen(port, function () {
log(`Package served at http://${hostname}:${port}/hypothesis`); log(`Package served at http://${hostname}:${port}/hypothesis`);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment