From 0d2090ba9fe24e82f4b0775abd7302e20d0ce909 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Wed, 4 Dec 2024 18:36:16 -0500 Subject: [PATCH] Initial commit --- Dockerfile | 21 +++++++++++++++++++++ docker-compose.yml | 13 +++++++++++++ package.json | 15 +++++++++++++++ src/app.js | 31 +++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 package.json create mode 100644 src/app.js diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cdb2596 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# Use the official Node.js 18 image as the base image +FROM node:18 + +# Set the working directory inside the container +WORKDIR /app + +# Copy package.json and package-lock.json (if available) +# (In this case, no dependencies are needed, so this step is optional) +COPY package*.json ./ + +# Install dependencies (optional step; no dependencies are required for this example) +# RUN npm install + +# Copy the server code into the container +COPY . . + +# Expose the port the server will run on +EXPOSE 3000 + +# Command to run the server +CMD ["node", "src/app.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e2669e9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3" + +networks: + proxnet: + external: true + +services: + websrv: + image: v0idf1sh/request-inspector + container_name: request-inspector + restart: unless-stopped + networks: + - proxnet \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..1066b61 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "request-inspector", + "version": "1.0.0", + "description": "Super basic node web server that displays all details of an HTTP request", + "main": "src/app.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://git.vfsh.dev/voidf1sh/request-inspector" + }, + "author": "voidf1sh", + "license": "ISC" +} diff --git a/src/app.js b/src/app.js new file mode 100644 index 0000000..f400cab --- /dev/null +++ b/src/app.js @@ -0,0 +1,31 @@ +// Import required modules +const http = require('http'); +const url = require('url'); + +// Create the server +const server = http.createServer((req, res) => { + // Parse the request URL + const parsedUrl = url.parse(req.url, true); + + // Prepare the response content + const responseContent = { + method: req.method, + url: req.url, + headers: req.headers, + query: parsedUrl.query, + }; + + // Set the response headers + res.writeHead(200, { 'Content-Type': 'application/json' }); + + // Send the response + res.end(JSON.stringify(responseContent, null, 2)); +}); + +// Define the server port +const PORT = 3000; + +// Start the server +server.listen(PORT, () => { + console.log(`Server is running on http://localhost:${PORT}`); +}); \ No newline at end of file