mirror of
https://github.com/postlight/mercury-parser
synced 2024-10-31 03:20:40 +00:00
60a6861e18
Big undertaking to support Mercury in the browser. Builds are working and all tests are passing both for web and node builds. Most code is closely shared.
40 lines
874 B
JavaScript
40 lines
874 B
JavaScript
/* eslint-disable */
|
|
const express = require('express'); // eslint-disable-line import/no-extraneous-dependencies
|
|
const request = require('request');
|
|
|
|
const app = express();
|
|
var server
|
|
|
|
const start = () => {
|
|
app.use('/', (req, res) => {
|
|
const url = req.url.slice(1);
|
|
|
|
const options = {
|
|
url,
|
|
// Don't set encoding; fixes issues
|
|
// w/gzipped responses
|
|
encoding: null,
|
|
// Accept cookies
|
|
jar: true,
|
|
// Accept and decode gzip
|
|
gzip: true,
|
|
// Follow any redirect
|
|
followAllRedirects: true,
|
|
};
|
|
req.pipe(request(options)).pipe(res);
|
|
});
|
|
|
|
server = app.listen(process.env.PORT || 3000);
|
|
}
|
|
|
|
const stop = () => {
|
|
server && server.close()
|
|
}
|
|
|
|
if (!process.env.CI) {
|
|
start()
|
|
require('child_process').execSync('./node_modules/karma/bin/karma start ./scripts/karma.conf.js', {stdio:[0,1,2]});
|
|
stop()
|
|
}
|
|
|