Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/signalk-plugin/src/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pkg from "../package.json" with { type: "json" };

/**
* Fetch wrapper that adds defaults like User-Agent header.
*/
export default function (url: string | URL, init: RequestInit = {}) {
return fetch(url, {
...init,
headers: {
...(init.headers || {}),
"User-Agent": `${pkg.name}/${pkg.version} (${pkg.homepage})`,
},
});
}
1 change: 1 addition & 0 deletions packages/signalk-plugin/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ServerAPI } from "@signalk/server-api";
import { readFile, writeFile } from "fs/promises";
import { join } from "path";
import { BATHY_URL } from "./constants.js";
import fetch from "./fetch.js";

export type Identity = {
uuid: string;
Expand Down
1 change: 1 addition & 0 deletions packages/signalk-plugin/src/reporters/noaa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "../streams/index.js";
import chain from "stream-chain";
import createDebug from "debug";
import fetch from "../fetch.js";

const debug = createDebug("crowd-depth:noaa");

Expand Down
1 change: 1 addition & 0 deletions packages/signalk-plugin/src/sources/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "@signalk/server-api/history";
import { Temporal } from "@js-temporal/polyfill";
import { BATHY_EPOCH } from "../constants.js";
import fetch from "../fetch.js";

export async function createHistorySource(
app: ServerAPI,
Expand Down
5 changes: 4 additions & 1 deletion packages/signalk-plugin/test/reporters/noaa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const data: BathymetryData[] = [

describe("submitGeoJSON", () => {
test("success", async () => {
const scope = nock(BATHY_URL).post("/geojson").reply(200, SUCCESS_RESPONSE);
const scope = nock(BATHY_URL)
.post("/geojson")
.matchHeader("user-agent", /^crowd-depth/)
.reply(200, SUCCESS_RESPONSE);
const res = await submitGeoJSON(
BATHY_URL,
config,
Expand Down