Commit 9cb80d10 authored by Robert Knight's avatar Robert Knight Committed by Lyza Gardner

Move all of the dev-server files to a top-level dev-server directory

Make it easier to explore all the code and resources that make up the
development server by putting them all in one directory.
parent 503b005d
This directory contains the Hypothesis client's development server that is
started by `make dev`. It hosts the assets that make up the Hypothesis client
from the `build/` directory as well as content for testing the Hypothesis client.
Test documents in the `documents/` directory are available at
`localhost:<port>/document/<filename-without-extension>`,
e.g. `documents/foo.mustache` would be available at `localhost:<port>/document/foo`.
Mustache-templated HTML documents may use `{{{ hypothesisScript }}}` to inject
the client application as configured by `templates/client-config.js.mustache`.
/* global __dirname */
'use strict';
const fs = require('fs');
......@@ -7,7 +9,8 @@ const Mustache = require('mustache');
const { createServer, useSsl } = require('./create-server');
const DOCUMENT_PATH = './test-documents/';
const DOCUMENT_PATH = `${__dirname}/documents/`;
const TEMPLATE_PATH = `${__dirname}/templates/`;
const DOCUMENT_PATTERN = /\.mustache/;
/**
......@@ -18,7 +21,7 @@ const DOCUMENT_PATTERN = /\.mustache/;
*/
function renderConfig(clientUrl) {
const scriptTemplate = fs.readFileSync(
`${DOCUMENT_PATH}client-config.js.mustache`,
`${TEMPLATE_PATH}client-config.js.mustache`,
'utf-8'
);
return Mustache.render(scriptTemplate, { clientUrl });
......@@ -87,8 +90,8 @@ function DevServer(port, config) {
);
} else {
content = injectClientScript(
`${DOCUMENT_PATH}404.mustache`,
config.clientUrl,
`${TEMPLATE_PATH}404.mustache`,
config.clientUrl
);
}
response.end(content);
......
......@@ -6,7 +6,7 @@ const express = require('express');
const log = require('fancy-log');
const { createServer, useSsl } = require('./create-server');
const { version } = require('../../package.json');
const { version } = require('../package.json');
/**
* An express server which serves the contents of the package.
......@@ -30,7 +30,7 @@ function servePackage(port) {
});
const serveBootScript = function (req, res) {
const entryPath = require.resolve('../..');
const entryPath = require.resolve('../');
const entryScript = readFileSync(entryPath).toString('utf-8');
res.send(entryScript);
};
......
......@@ -16,7 +16,7 @@ const through = require('through2');
const createBundle = require('./scripts/gulp/create-bundle');
const createStyleBundle = require('./scripts/gulp/create-style-bundle');
const manifest = require('./scripts/gulp/manifest');
const servePackage = require('./scripts/gulp/serve-package');
const servePackage = require('./dev-server/serve-package');
const vendorBundles = require('./scripts/gulp/vendor-bundles');
const IS_PRODUCTION_BUILD = process.env.NODE_ENV === 'production';
......@@ -294,7 +294,7 @@ gulp.task('serve-package', function () {
});
gulp.task('serve-test-pages', function () {
const DevServer = require('./scripts/gulp/dev-server');
const DevServer = require('./dev-server');
new DevServer(3000, {
// The scheme is omitted here as the client asset server will use the same
// protcol (HTTP or HTTPS) as the test page server.
......
This directory contains documents that are served by the local
web server (via `make dev`). Files here with a `.mustache.html` extension
will be available in the browser at the path
`localhost:<port>/document/<filename-without-extension>`,
e.g. `foo.mustache.html` would be available at `localhost:<port>/document/foo`.
Mustache-templated HTML documents may use `{{{ hypothesisScript }}}` to inject
the client application as configured by `client-config.js.mustache`.
Other things here:
- `client-config.js.mustache` - configuration for the client and JS to inject
the client into HTML pages. You can make edits here if you'd like to
change how the application is configured in the local web pages.
- `index.template.mustache` is the main "landing page" for the local dev server.
- `preformatted.template.mustach` is a template used to render some additional content
used by `index.template.mustache`
See `scripts/gulp/dev-server.js` for more information on how these files
are composed.
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