-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (22 loc) · 876 Bytes
/
server.js
File metadata and controls
27 lines (22 loc) · 876 Bytes
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
const express = require('express');
const axios = require('axios');
const cheerio = require('cheerio');
const cors = require('cors'); // Import the cors package
const app = express();
const PORT = 3000;
app.use(cors()); // Enable CORS for all routes
app.get('/daily-word', async (req, res) => {
try {
const response = await axios.get('https://ordnet.dk/ddo');
const $ = cheerio.load(response.data);
// Extract the word (you'll need to inspect the HTML structure of the page)
const word = $('.match').text().trim(); // Use .text() instead of .textContent
res.json({ word });
} catch (error) {
console.error('Error fetching the word:', error);
res.status(500).json({ error: 'Failed to fetch the word' });
}
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});