-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (26 loc) · 821 Bytes
/
server.js
File metadata and controls
30 lines (26 loc) · 821 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
28
29
30
import cors from "cors";
import express from "express";
import fetch from "node-fetch";
import path, { dirname } from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const app = express();
app.use(cors());
app.use(express.static(path.resolve(__dirname, "dist")));
app.use("/:difficulty", async (req, res) => {
try {
const { difficulty } = req.params;
const response = await fetch(`https://sudoku.com/api/level/${difficulty}`, {
headers: {
"x-requested-with": "XMLHttpRequest",
},
});
const data = await response.json();
res.send(data);
} catch (e) {
res.send({});
}
});
const port = process.env.PORT || 3001;
app.listen(port, () => console.log(`Server running on port ${port}`));