Skip to content
Snippets Groups Projects
Commit 7eaa9843 authored by De Brettes Thomas's avatar De Brettes Thomas
Browse files

Changement

parent bf513292
No related branches found
No related tags found
No related merge requests found
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jeu d'échecs</title>
<style>
canvas {
border: 2px solid black;
display: block;
margin: 20px auto;
}
</style>
</head>
<body>
<h1>Jeu d'échecs</h1>
<canvas id="chessboard" width="480" height="480"></canvas>
<script src="chess.js"></script>
</body>
</html>
var fs = require('fs'),
http = require('http'),
path = require('path');
const canvas = document.getElementById("chessboard"); var server = http.createServer(function (request, response) {
const ctx = canvas.getContext("2d"); var filePath = path.join(__dirname, 'htdocs', request.url === '/' ? 'index.html' : request.url);
const size = 60;
for (let row = 0; row < 8; row++) { fs.readFile(filePath, function (err, data) {
for (let col = 0; col < 8; col++) { if (err) {
ctx.fillStyle = (row + col) % 2 === 0 ? "white" : "black"; response.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
ctx.fillRect(col * size, row * size, size, size); response.end('Désolé, le document demandé est introuvable...');
} console.log('404 ' + request.url);
} else {
let ext = path.extname(filePath);
let contentType = 'text/html';
if (ext === '.css') contentType = 'text/css';
if (ext === '.js') contentType = 'application/javascript';
response.writeHead(200, { 'Content-Type': contentType + '; charset=utf-8' });
response.end(data);
console.log('200 ' + request.url);
} }
});
});
server.listen(8080, () => {
console.log("Serveur démarré sur http://localhost:8080");
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment