From d689b4b6841e5554c8716be70eb28d629be2bd68 Mon Sep 17 00:00:00 2001 From: Alex Mickelson Date: Fri, 15 Nov 2024 14:38:53 -0700 Subject: [PATCH] adding file polling for windows machines --- nextjs/docker-compose.yml | 1 + nextjs/package.json | 3 ++- nextjs/pnpm-lock.yaml | 15 ++++++++++++--- nextjs/src/app/newCourse/NewCourseForm.tsx | 1 + nextjs/src/websocket.js | 10 +++++++++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/nextjs/docker-compose.yml b/nextjs/docker-compose.yml index 2465b42..5090ff2 100644 --- a/nextjs/docker-compose.yml +++ b/nextjs/docker-compose.yml @@ -10,6 +10,7 @@ services: environment: - storageDirectory=/app/storage - TZ=America/Denver + # - FILE_POLLING=true volumes: - ~/projects/faculty/1430/2024-fall-alex/modules:/app/storage/UX - ~/projects/faculty/4850_AdvancedFE/2024-fall-alex/modules:/app/storage/advanced_frontend diff --git a/nextjs/package.json b/nextjs/package.json index 64886ea..83f7694 100644 --- a/nextjs/package.json +++ b/nextjs/package.json @@ -19,6 +19,7 @@ "@trpc/server": "11.0.0-rc.608", "@types/ws": "^8.5.13", "chokidar": "^4.0.1", + "dotenv": "^16.4.5", "jsdom": "^25.0.0", "next": "^15.0.2", "react": "^18", @@ -32,7 +33,6 @@ "@monaco-editor/loader": "^1.4.0", "@monaco-editor/react": "^4.6.0", "@testing-library/dom": "^10.4.0", - "socket.io-client": "^4.8.1", "@testing-library/react": "^16.0.0", "@types/node": "^22", "@types/react": "^18", @@ -46,6 +46,7 @@ "postcss": "^8", "react-error-boundary": "^4.0.13", "react-hot-toast": "^2.4.1", + "socket.io-client": "^4.8.1", "tailwindcss": "^3.4.1", "typescript": "^5", "vitest": "^2.0.5", diff --git a/nextjs/pnpm-lock.yaml b/nextjs/pnpm-lock.yaml index 7040af8..64a398e 100644 --- a/nextjs/pnpm-lock.yaml +++ b/nextjs/pnpm-lock.yaml @@ -29,6 +29,9 @@ importers: chokidar: specifier: ^4.0.1 version: 4.0.1 + dotenv: + specifier: ^16.4.5 + version: 16.4.5 jsdom: specifier: ^25.0.0 version: 25.0.1 @@ -44,9 +47,6 @@ importers: socket.io: specifier: ^4.8.1 version: 4.8.1 - socket.io-client: - specifier: ^4.8.1 - version: 4.8.1 superjson: specifier: ^2.2.1 version: 2.2.1 @@ -105,6 +105,9 @@ importers: react-hot-toast: specifier: ^2.4.1 version: 2.4.1(csstype@3.1.3)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + socket.io-client: + specifier: ^4.8.1 + version: 4.8.1 tailwindcss: specifier: ^3.4.1 version: 3.4.14(ts-node@10.9.2(@types/node@22.9.0)(typescript@5.6.3)) @@ -1256,6 +1259,10 @@ packages: dompurify@3.1.7: resolution: {integrity: sha512-VaTstWtsneJY8xzy7DekmYWEOZcmzIe3Qb3zPd4STve1OBTa+e+WmS1ITQec1fZYXI3HCsOZZiSMpG6oxoWMWQ==} + dotenv@16.4.5: + resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==} + engines: {node: '>=12'} + eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} @@ -3801,6 +3808,8 @@ snapshots: dompurify@3.1.7: {} + dotenv@16.4.5: {} + eastasianwidth@0.2.0: {} electron-to-chromium@1.5.53: {} diff --git a/nextjs/src/app/newCourse/NewCourseForm.tsx b/nextjs/src/app/newCourse/NewCourseForm.tsx index 69c18ba..afcc51a 100644 --- a/nextjs/src/app/newCourse/NewCourseForm.tsx +++ b/nextjs/src/app/newCourse/NewCourseForm.tsx @@ -31,6 +31,7 @@ const sampleCompose = `services: - .env # needs to have your CANVAS_TOKEN set environment: - TZ=America/Denver # prevents timezone issues for due dates + # - FILE_POLLING=true # increases cpu usage, uncomment if source volumes are on ntfs volumes: - ~/projects/faculty/1430/2024-fall-alex/modules:/app/storage/UX - ~/projects/faculty/4850_AdvancedFE/2024-fall-alex/modules:/app/storage/advanced_frontend diff --git a/nextjs/src/websocket.js b/nextjs/src/websocket.js index d214c4d..9e935d2 100644 --- a/nextjs/src/websocket.js +++ b/nextjs/src/websocket.js @@ -3,6 +3,8 @@ import next from "next"; import { Server } from "socket.io"; import chokidar from "chokidar"; import path from "path"; +import dotenv from "dotenv"; +dotenv.config(); const dev = process.env.NODE_ENV !== "production"; const hostname = "localhost"; @@ -14,12 +16,18 @@ const handler = app.getRequestHandler(); const folderToWatch = path.join(process.cwd(), "./storage", "/"); console.log("watching folder", folderToWatch); +const usePolling = process.env.FILE_POLLING === "true"; +console.log("FILE_POLLING:", usePolling); + +const watcher = chokidar.watch(folderToWatch, { + persistent: true, + usePolling, +}); app.prepare().then(() => { const httpServer = createServer(handler); const io = new Server(httpServer); - const watcher = chokidar.watch(folderToWatch, { persistent: true }); io.on("connection", (socket) => { console.log("websocket connection created");