Skip to content
Snippets Groups Projects
Commit ffb8dc75 authored by LeonLicher's avatar LeonLicher
Browse files

added router to /solution where the solution is displayed not yet formatted as...

added router to /solution where the solution is displayed not yet formatted as text + using express instead of http directly
parent e6fd4400
No related branches found
No related tags found
No related merge requests found
import { solveSudoku } from "./solver.js";
import http from 'node:http';
import { generateSudoku } from "./generateSudoku.js";
import express from "express"
const sudokuBoard = generateSudoku(81)
const sudokuBoard = generateSudoku(50)
console.log(sudokuBoard)
const rawString = sudokuBoard.map(row => row.map(num => `<td>${num}</td>`).join('')).map(row => `<tr>${row}</tr>`).join('');
......@@ -78,16 +79,25 @@ const htmlResponse = `
</html>
`;
const router = express.Router();
const port = 8080;
let app = express()
const server = http.createServer((req, res) => {
app.get("/",(req, res) => {
app.use('/solution', router);
res.statusCode = 200;
res.end(htmlResponse);
});
router.get("/solution", (req, res) => {
server.listen(port, () => {
res.end(solString)
})
app.use(router)
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
......
This diff is collapsed.
This diff is collapsed.
......@@ -12,6 +12,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2",
"ws": "^8.15.0"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment