mirror of
https://github.com/trambarhq/relaks-wordpress-example.git
synced 2025-09-02 12:42:38 +02:00
Using keepalive connection when fetching.
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
const CrossFetch = require('cross-fetch');
|
||||
|
||||
const WORDPRESS_HOST = process.env.WORDPRESS_HOST;
|
||||
const WORDPRESS_PROTOCOL = 'http' + (/^https:/.test(WORDPRESS_HOST) ? 's' : '');
|
||||
|
||||
let agent = new require(WORDPRESS_PROTOCOL).Agent({ keepAlive: true });
|
||||
|
||||
async function fetch(path) {
|
||||
console.log(`Retrieving data: ${path}`);
|
||||
let url = `${WORDPRESS_HOST}${path}`;
|
||||
let res = await CrossFetch(url);
|
||||
let res = await CrossFetch(url, { agent });
|
||||
let resText = await res.text();
|
||||
let object;
|
||||
try {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
const Bluebird = require('bluebird');
|
||||
const FS = Bluebird.promisifyAll(require('fs'));
|
||||
const ReactDOMServer = require('react-dom/server');
|
||||
const HTTP = require('http');
|
||||
const CrossFetch = require('cross-fetch');
|
||||
const FrontEnd = require('./client/front-end');
|
||||
|
||||
@@ -15,10 +16,12 @@ async function generate(path, target) {
|
||||
let host = NGINX_HOST;
|
||||
// create a fetch() that remembers the URLs used
|
||||
let sourceURLs = [];
|
||||
let agent = new HTTP.Agent({ keepAlive: true });
|
||||
let fetch = (url, options) => {
|
||||
if (url.startsWith(host)) {
|
||||
sourceURLs.push(url.substr(host.length));
|
||||
options = addHostHeader(options);
|
||||
options.agent = agent;
|
||||
}
|
||||
return CrossFetch(url, options);
|
||||
};
|
||||
|
Reference in New Issue
Block a user