Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
prettier --check "**/*.{js,scss,html}"
prettier --check "**/*.{ts,js,scss,html}"
2 changes: 2 additions & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require: 'ts-node/register'
spec: 'test/**/*.test.ts'
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ FROM node:24.14.0-alpine AS builder
WORKDIR /app

COPY package*.json ./
RUN npm ci
RUN npm install

COPY static/scss/ ./static/scss/
COPY httpconfig.ts tsconfig.json ./
RUN npm run build

FROM node:24.14.0-alpine

WORKDIR /app

COPY package*.json ./
RUN npm ci --omit=dev
RUN npm install --omit=dev

COPY httpconfig.js ./
COPY --from=builder /app/dist/httpconfig.js ./httpconfig.js
COPY static/html/ ./static/html/
COPY static/js/ ./static/js/
COPY --from=builder /app/static/css/ ./static/css/
Expand Down
89 changes: 89 additions & 0 deletions httpconfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import compression from 'compression';
import dns from 'dns';
import express, { NextFunction, Request, Response } from 'express';
import path from 'path';

interface RequestField {
displayName: string;
value: string | string[] | undefined;
}

interface RemoteRequest {
ip: RequestField;
hostname: RequestField;
ua: RequestField;
language: RequestField;
connection: RequestField;
encoding: RequestField;
mimeType: RequestField;
charset: RequestField;
}

const app = express();
const port = parseInt(process.env.PORT ?? '9000', 10);

app.set('trust proxy', true);

app.use(compression());
app.use('/static', express.static(path.join(__dirname, 'static')));

app.get('/', (req: Request, res: Response) => {
res.sendFile(path.join(__dirname, 'static/html/httpconfig.html'));
});

app.get('/api/httpconfig', (req: Request, res: Response) => {
const remoteReq: RemoteRequest = {
ip: {
displayName: 'IP Address',
value: req.ip,
},
hostname: {
displayName: 'Remote Host',
value: '',
},
ua: {
displayName: 'User Agent',
value: req.headers['user-agent'],
},
language: {
displayName: 'Language',
value: req.headers['accept-language'],
},
connection: {
displayName: 'Connection',
value: req.headers.connection,
},
encoding: {
displayName: 'Encoding',
value: req.headers['accept-encoding'],
},
mimeType: {
displayName: 'MIME Type',
value: req.headers.accept,
},
charset: {
displayName: 'Charset',
value: req.headers['accept-charset'],
},
};

dns.reverse(req.ip ?? '', (err, domains) => {
if (domains) {
remoteReq.hostname.value = domains[0];
}

res.json(remoteReq);
});
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
app.use((req: Request, res: Response, next: NextFunction) => {
res.status(404).send("404: Sorry, we've had an error.");
});

if (require.main === module) {
app.listen(port);
console.log('Listening on port ' + port);
}

export default app;
Loading
Loading