initial commit
This commit is contained in:
29
index.ts
Normal file
29
index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user