Initial commit

This commit is contained in:
Skylar Grant 2024-12-04 18:36:16 -05:00
parent 1d430902f2
commit 0d2090ba9f
4 changed files with 80 additions and 0 deletions

21
Dockerfile Normal file
View File

@ -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"]

13
docker-compose.yml Normal file
View File

@ -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

15
package.json Normal file
View File

@ -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"
}

31
src/app.js Normal file
View File

@ -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}`);
});