diff --git a/src/commands/dev/dev.ts b/src/commands/dev/dev.ts index 9b102a05ca3..0d2440a30f8 100644 --- a/src/commands/dev/dev.ts +++ b/src/commands/dev/dev.ts @@ -218,6 +218,7 @@ export const dev = async (options: OptionValues, command: BaseCommand) => { await startProxyServer({ addonsUrls, + api, blobsContext, command, config: mutatedConfig, diff --git a/src/utils/proxy-server.ts b/src/utils/proxy-server.ts index 5d7749a333e..157293f2397 100644 --- a/src/utils/proxy-server.ts +++ b/src/utils/proxy-server.ts @@ -42,6 +42,7 @@ export const generateInspectSettings = ( export const startProxyServer = async ({ accountId, addonsUrls, + api, blobsContext, command, config, @@ -64,6 +65,7 @@ export const startProxyServer = async ({ }: { accountId: string addonsUrls: $TSFixMe + api?: NetlifyOptions['api'] blobsContext?: BlobsContextWithEdgeAccess command: BaseCommand config: NetlifyOptions['config'] @@ -106,6 +108,7 @@ export const startProxyServer = async ({ siteInfo, accountId, repositoryRoot, + api, }) if (!url) { log(NETLIFYDEVERR, `Unable to start proxy server on port '${settings.port}'`) diff --git a/src/utils/proxy.ts b/src/utils/proxy.ts index b8ec2d21bae..e5ff3762708 100644 --- a/src/utils/proxy.ts +++ b/src/utils/proxy.ts @@ -5,6 +5,7 @@ import http, { ServerResponse } from 'http' import https from 'https' import { isIPv6 } from 'net' import path from 'path' +import process from 'process' import { Duplex } from 'stream' import util from 'util' import zlib from 'zlib' @@ -24,6 +25,7 @@ import { locatePath } from 'locate-path' import { Match } from 'netlify-redirector' import pFilter from 'p-filter' import toReadableStream from 'to-readable-stream' +import throttle from 'lodash/throttle.js' import { BaseCommand } from '../commands/index.js' import { $TSFixMe, NetlifyOptions } from '../commands/types.js' @@ -230,6 +232,13 @@ const alternativePathsFor = function (url) { return paths } +const notifyActivity = throttle((api: NetlifyOptions['api'], siteId: string, devServerId: string) => { + // eslint-disable-next-line promise/prefer-await-to-callbacks, promise/prefer-await-to-then + api.markDevServerActivity({ siteId, devServerId }).catch((error) => { + console.error(`${NETLIFYDEVWARN} Failed to notify activity`, error) + }) +}, 30 * 1000) + const serveRedirect = async function ({ env, functionsRegistry, @@ -718,6 +727,7 @@ const initializeProxy = async function ({ const onRequest = async ( { addonsUrls, + api, edgeFunctionsProxy, env, functionsRegistry, @@ -790,6 +800,10 @@ const onRequest = async ( framework: settings.framework, } + if (api && process.env.NETLIFY_DEV_SERVER_ID) { + notifyActivity(api, siteInfo.id, process.env.NETLIFY_DEV_SERVER_ID) + } + if (match) { // We don't want to generate an ETag for 3xx redirects. // @ts-expect-error TS(7031) FIXME: Binding element 'statusCode' implicitly has an 'an... Remove this comment to see the full error message @@ -831,6 +845,7 @@ type EdgeFunctionsProxy = Awaited