26 lines
679 B
JavaScript
26 lines
679 B
JavaScript
const https = require('https');
|
|
const fs = require('fs');
|
|
|
|
const options = {
|
|
key: fs.readFileSync('server-key.pem'),
|
|
cert: fs.readFileSync('server-cert.pem'),
|
|
};
|
|
|
|
const server = https.createServer(options, (req, res) => {
|
|
|
|
// Handle your request logic here
|
|
if (req.method === 'GET' && req.url === '/') {
|
|
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
res.end('Hello, HTTPS Server!');
|
|
} else {
|
|
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
res.end('Not Found');
|
|
}
|
|
});
|
|
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
server.listen(PORT, () => {
|
|
console.log(`Server is running at https://localhost:${PORT}/`);
|
|
});
|