Files
rickroll/index.ts
ytshih 29793e655c
All checks were successful
deploy / release-image (push) Successful in 1m47s
deploy / deploy (push) Successful in 46s
initial commit
2024-10-17 07:51:46 +00:00

30 lines
661 B
TypeScript

import { createServer, IncomingMessage, ServerResponse } from 'http';
import 'dotenv/config';
const config = {
port: process.env.PORT ?? 80,
uri: process.env.URI ?? 'https://youtu.be/dQw4w9WgXcQ'
};
const httpServer = createServer();
async function handleHttpRequests(
req: IncomingMessage,
res: ServerResponse
): Promise<ServerResponse> {
res.writeHead(302, { Location: config.uri });
return res.end();
}
async function main() {
try {
httpServer.listen(config.port);
httpServer.on('request', handleHttpRequests);
console.log(`Listen on ${config.port}.`);
} catch(err: unknown) {
console.log(`Error, ${err}`);
}
}
main();