DEV: Update node-fetch (#19059)

node-fetch is now a ES module, so it has to either imported with `import/from` syntax (which can't be used in addon's index.js) or using the dynamic `import()`
This commit is contained in:
Jarek Radosz
2022-11-16 18:58:38 +01:00
committed by GitHub
parent 6d6d5a200f
commit a7b033d642
4 changed files with 43 additions and 4 deletions

View File

@@ -1,7 +1,6 @@
"use strict";
const express = require("express");
const fetch = require("node-fetch");
const { encode } = require("html-entities");
const cleanBaseURL = require("clean-base-url");
const path = require("path");
@@ -258,6 +257,7 @@ async function buildFromBootstrap(proxy, baseURL, req, response, preload) {
url.searchParams.append("preview_theme_id", reqUrlPreviewThemeId);
}
const { default: fetch } = await import("node-fetch");
const res = await fetch(url, { headers: req.headers });
const json = await res.json();
@@ -310,6 +310,7 @@ async function handleRequest(proxy, baseURL, req, res) {
req.headers["X-Discourse-Ember-CLI"] = "true";
}
const { default: fetch } = await import("node-fetch");
const response = await fetch(url, {
method: req.method,
body: /GET|HEAD/.test(req.method) ? null : req.body,

View File

@@ -25,6 +25,6 @@
"express": "^4.18.2",
"html-entities": "^2.3.3",
"jsdom": "^20.0.2",
"node-fetch": "^2.6.6"
"node-fetch": "^3.3.0"
}
}