Использование Cloudflare Worker для HTTP / 2-сервера Pu sh Stati c Содержание - PullRequest
0 голосов
/ 19 апреля 2020

У меня ниже Cloudflare рабочий, через который я могу http2 сервер pu sh stati c files.

addEventListener('fetch', event => {
  event.respondWith(handle(event.request))
})

async function handle(request) {
  // Check for returning users's cookie.
  let cookies = request.headers.get('Cookie') || ""
  if (cookies.includes("returning=true")) {
    // User has been here before. Just pass request through.
    return fetch(request);
  }

  // Forward request to origin, get response.
  let response = await fetch(request);

  // Copy Response object so that we can edit headers.
  response = new Response(response.body, response);

  //push fonts
  response.headers.append("Link", "</content/fonts/roboto-v20-latin-regular.woff2>; rel=preload; as=font;");
  response.headers.append("Link", "</content/fonts/raleway-v14-latin-regular.woff2>; rel=preload; as=font;");
  response.headers.append("Link", "</content/fonts/material-icons.woff2>; rel=preload; as=font;");

  //push css
  response.headers.append("Link", "</styles.b5424d5be1c9914c735a.css>; rel=preload; as=style;");

//push javascript
  response.headers.append("Link", "</runtime-es2015.47f2a519ea196da5b8f0.js>; rel=preload; as=script;");
  response.headers.append("Link", "</polyfills-es2015.37022e3161e137aeda94.js>; rel=preload; as=script;");
  response.headers.append("Link", "</main-es2015.42ab1e6805d180015b84.js>; rel=preload; as=script;");

  // Set cookie so that we don't add the headers next time.
  response.headers.set('Set-Cookie', "returning=true")

  // Return on to client.
  return response;
}

Это работает нормально, но проблема в том, как вы можете видеть из кода, который имена файлов css и javascript имеют хэшированные значения, и имена этих файлов генерируются автоматически при создании производственной сборки моего веб-приложения.

Таким образом, в настоящее время всякий раз, когда я развертываю свое приложение Мне нужно обновить имена файлов css и javascript в моем работнике cloudflare.

Любая идея, как заставить работника Cloudflare проверять html (ответ от исходного сервера) и автоматически добавлять http / 2 Сервер Pu sh Заголовки для pu sh все содержимое c (css и javascript) на этой странице.

Любая помощь будет высоко оценена:)

...