From 5c0b823c12ce172c61ea7a4c1b60c3142a2af719 Mon Sep 17 00:00:00 2001 From: Aarnav Tale Date: Sat, 30 Mar 2024 04:20:16 -0400 Subject: [PATCH] fix: replace chokidar with fs.watch --- app/routes/_data.dns._index/route.tsx | 2 ++ app/utils/config.ts | 5 +++-- package.json | 1 - pnpm-lock.yaml | 3 --- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/routes/_data.dns._index/route.tsx b/app/routes/_data.dns._index/route.tsx index 177a694..b2ccfd4 100644 --- a/app/routes/_data.dns._index/route.tsx +++ b/app/routes/_data.dns._index/route.tsx @@ -12,6 +12,7 @@ import Spinner from '~/components/Spinner' import TableList from '~/components/TableList' import { getConfig, getContext, patchConfig } from '~/utils/config' import { restartHeadscale } from '~/utils/docker' +import { useLiveData } from '~/utils/useLiveData' import Domains from './domains' import MagicModal from './magic' @@ -56,6 +57,7 @@ export async function action({ request }: ActionFunctionArgs) { } export default function Page() { + useLiveData({ interval: 5000 }) const data = useLoaderData() const fetcher = useFetcher() const [localOverride, setLocalOverride] = useState(data.overrideLocal) diff --git a/app/utils/config.ts b/app/utils/config.ts index eb57271..5c083d0 100644 --- a/app/utils/config.ts +++ b/app/utils/config.ts @@ -1,7 +1,7 @@ +import { type FSWatcher, watch } from 'node:fs' import { access, constants, readFile, writeFile } from 'node:fs/promises' import { resolve } from 'node:path' -import { type FSWatcher, watch } from 'chokidar' import { type Document, parseDocument } from 'yaml' type Duration = `${string}s` | `${string}h` | `${string}m` | `${string}d` | `${string}y` @@ -149,7 +149,8 @@ export function registerConfigWatcher() { } const path = resolve(process.env.CONFIG_FILE ?? '/etc/headscale/config.yaml') - watcher = watch(path).on('change', async () => { + watcher = watch(path, async () => { + console.log('Config file changed, reloading') await getConfig(true) }) } diff --git a/package.json b/package.json index 5a881ab..f2b5eb0 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "@remix-run/node": "^2.8.1", "@remix-run/react": "^2.8.1", "@remix-run/serve": "^2.8.1", - "chokidar": "^3.6.0", "clsx": "^2.1.0", "isbot": "^4.1.0", "oauth4webapi": "^2.10.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 623c5d7..b744b87 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,9 +32,6 @@ dependencies: '@remix-run/serve': specifier: ^2.8.1 version: 2.8.1(typescript@5.4.3) - chokidar: - specifier: ^3.6.0 - version: 3.6.0 clsx: specifier: ^2.1.0 version: 2.1.0