var https = require('https'); var fs = require('fs'); // Read the certificate and the…
- User
var https = require('https'); var fs = require('fs');
// Read the certificate and the private key from the files var options = { key: fs.readFileSync('key.pem'), cert: fs.readFileSync('cert.pem') };
// Create a HTTPS server with the options var server = https.createServer(options, function(request, response) { // Your original code goes here const url = new URL(request.url); const provider = url.searchParams.get("subs");
let links = []; if (provider === "IRC") { links = [ 'xxxxxx', 'xxxxxx', 'xxxxxx' ]; } else if (provider === "MCI") { links = [ 'xxxxxx' ]; }
const responseText = links.join('\n').replace(/,/g, '\n');
// Encoding the response text in base64 const encodedResponse = btoa(responseText);
response.writeHead(200, { 'Content-Type': 'text/plain' }); response.end(encodedResponse); });
// Listen on port 8080 server.listen(8080);
vs // Importing the https module const https = require('https');
// Creating the options object with the SSL/TLS configuration const options = { key: fs.readFileSync('key.pem'), cert: fs.readFileSync('cert.pem') };
// Creating the https.Server object const server = https.createServer(options, async function handleRequest(request) { // How to create a subscribe link and give it to the family with iSegaro const url = new URL(request.url); const provider = url.searchParams.get("subs");
let links = []; if (provider === "IRC") { links = [ 'xxxxxx', 'xxxxxx', 'xxxxxx' ]; } else if (provider === "MCI") { links = [ 'xxxxxx' ]; }
const responseText = links.join('\n').replace(/,/g, '\n');
// Encoding the response text in base64 const encodedResponse = btoa(responseText);
return new Response(encodedResponse, { headers: { 'Content-Type': 'text/plain' }, }); });
// Listening for requests on port 443 server.listen(443, function() { console.log('Server is running on https://localhost:443'); });
// Handling errors server.on('error', function(error) { console.error(error); });
- Assistant
- User
how to make it into https ? async function handleRequest(request) { // How to create a subscribe link and give it to the family with iSegaro const url = new URL(request.url); const provider = url.searchParams.get("subs");
let links = []; if (provider === "IRC") { links = [ 'xxxxxx', 'xxxxxx', 'xxxxxx' ]; } else if (provider === "MCI") { links = [ 'xxxxxx' ]; } const responseText = links.join('\n').replace(/,/g, '\n'); // Encoding the response text in base64 const encodedResponse = btoa(responseText); return new Response(encodedResponse, { headers: { 'Content-Type': 'text/plain' }, });}
addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)); });
- Assistant