-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
32 lines (27 loc) · 918 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Require necessary modules
const http = require('http');
const fs = require('fs');
require('dotenv').config();
// Read the API key from the environment variables
const apiKey = process.env.API_KEY;
// Create a server
const server = http.createServer((req, res) => {
// Read the HTML file
fs.readFile('main.html', 'utf8', (err, data) => {
if (err) {
res.writeHead(500);
res.end('Error reading file');
return;
}
// Replace the placeholder {{API_KEY}} with the actual API key
const modifiedHtml = data.replace('{{API_KEY}}', apiKey);
// Send the modified HTML content to the client
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(modifiedHtml);
});
});
// Start the server
const PORT = process.env.PORT || 3001;
server.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});