-
Notifications
You must be signed in to change notification settings - Fork 4
feat: motd #361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: motd #361
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"status": "up", | ||
"message": "Registry service is running" | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,13 +1,29 @@ | ||||||||||||||||||||||||||||||||||||
import fastify from "fastify"; | ||||||||||||||||||||||||||||||||||||
import { generateEntropy, generatePlatformToken, getJWK } from "./jwt"; | ||||||||||||||||||||||||||||||||||||
import dotenv from "dotenv"; | ||||||||||||||||||||||||||||||||||||
import path from "path"; | ||||||||||||||||||||||||||||||||||||
import path from "node:path"; | ||||||||||||||||||||||||||||||||||||
import { AppDataSource } from "./config/database"; | ||||||||||||||||||||||||||||||||||||
import { VaultService } from "./services/VaultService"; | ||||||||||||||||||||||||||||||||||||
import { UriResolutionService } from "./services/UriResolutionService"; | ||||||||||||||||||||||||||||||||||||
import { KubernetesService } from "./services/KubernetesService"; | ||||||||||||||||||||||||||||||||||||
import cors from "@fastify/cors"; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
import fs from "node:fs"; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
function loadMotdJSON() { | ||||||||||||||||||||||||||||||||||||
const motdJSON = fs.readFileSync(path.resolve(__dirname, "../motd.json"), "utf8"); | ||||||||||||||||||||||||||||||||||||
return JSON.parse(motdJSON) as { | ||||||||||||||||||||||||||||||||||||
status: "up" | "maintenance" | ||||||||||||||||||||||||||||||||||||
message: string | ||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
let motd = loadMotdJSON(); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
fs.watchFile(path.resolve(__dirname, "../motd.json"), (_curr, _prev) => { | ||||||||||||||||||||||||||||||||||||
motd = loadMotdJSON(); | ||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Major: Use
Apply this diff to use event-based watching with proper cleanup: -fs.watchFile(path.resolve(__dirname, "../motd.json"), (_curr, _prev) => {
- motd = loadMotdJSON();
-});
+const motdWatcher = fs.watch(
+ path.resolve(__dirname, "../motd.json"),
+ async (eventType) => {
+ if (eventType === "change") {
+ motd = await loadMotdJSON();
+ server.log.info("MOTD reloaded");
+ }
+ }
+);
+
+// Cleanup on server close
+server.addHook("onClose", async () => {
+ motdWatcher.close();
+}); Note: This assumes you've converted 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
dotenv.config({ path: path.resolve(__dirname, "../../../.env") }); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
const server = fastify({ logger: true }); | ||||||||||||||||||||||||||||||||||||
|
@@ -55,6 +71,10 @@ const checkSharedSecret = async (request: any, reply: any) => { | |||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
server.get("/motd", async (request, reply) => { | ||||||||||||||||||||||||||||||||||||
return motd; | ||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
// Create a new vault entry | ||||||||||||||||||||||||||||||||||||
server.post( | ||||||||||||||||||||||||||||||||||||
"/register", | ||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Synchronous I/O blocks the event loop and lacks error handling.
The implementation has several serious issues:
fs.readFileSync
blocks the event loop during startup and file reloads, degrading server responsiveness.__dirname
may not resolve correctly after TypeScript compilation, depending on build configuration.Apply this diff to use async I/O with proper error handling:
Note: You'll also need to update the file watcher (see next comment).
Also applies to: 13-19, 21-21