heureka
This commit is contained in:
1 parent
6d2239cc39
commit
2cc5981bba
18 files changed
+618
-204
No files matched your search
@@ -0,0 +1,20 @@
|
||||
# Use the official Node.js image
|
||||
FROM node:14
|
||||
|
||||
# Create and set the working directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy package.json and package-lock.json to the working directory
|
||||
COPY package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm install
|
||||
|
||||
# Copy the server.js file to the working directory
|
||||
COPY server.js .
|
||||
|
||||
# Expose the port the app runs on
|
||||
EXPOSE 3000
|
||||
|
||||
# Command to run the application
|
||||
CMD ["node", "server.js"]
|
||||
@@ -0,0 +1,44 @@
|
||||
const http = require("http");
|
||||
const url = require("url");
|
||||
|
||||
const logs = [];
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
const parsedUrl = url.parse(req.url, true);
|
||||
|
||||
if (req.method === "GET") {
|
||||
if (parsedUrl.pathname === "/logs") {
|
||||
// Respond with all logs
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify(logs));
|
||||
} else if (parsedUrl.pathname === "/clear") {
|
||||
// Clear all logs
|
||||
logs.length = 0;
|
||||
res.writeHead(200, { "Content-Type": "text/plain" });
|
||||
res.end("Logs cleared\n");
|
||||
} else {
|
||||
// Extract the value of the 'message' query parameter
|
||||
const message = parsedUrl.query.message || "No message provided";
|
||||
|
||||
// Log the message
|
||||
logs.push({ timestamp: new Date().toISOString(), message });
|
||||
|
||||
// Log the message to the console
|
||||
console.log("Received message:", message);
|
||||
|
||||
// Send a response to the client
|
||||
res.writeHead(200, { "Content-Type": "text/plain" });
|
||||
res.end("Message received\n");
|
||||
}
|
||||
} else {
|
||||
// Handle other HTTP methods (e.g., POST, PUT, DELETE)
|
||||
res.writeHead(404, { "Content-Type": "text/plain" });
|
||||
res.end("Not Found\n");
|
||||
}
|
||||
});
|
||||
|
||||
const PORT = 3000;
|
||||
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Server listening on port ${PORT}`);
|
||||
});
|
||||
Reference in new issue
Block a user