Spaces:
Paused
Paused
T1ckbase
commited on
Commit
·
7910130
1
Parent(s):
0888b0c
add custom logger
Browse files
main.ts
CHANGED
|
@@ -10,6 +10,21 @@ const minesweeper = new Minesweeper(8, 8, MINE_COUNT, './images');
|
|
| 10 |
|
| 11 |
const app = new Hono();
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
app.get('/', (c) => c.text(`Play minesweeper:\nhttps://github.com/${USER}`));
|
| 14 |
|
| 15 |
app.get('/headers', (c) => c.text(Array.from(c.req.raw.headers).join('\n')));
|
|
@@ -32,7 +47,7 @@ app.get('/cell/:row/:col/image', (c) => {
|
|
| 32 |
return c.body(cellImage);
|
| 33 |
});
|
| 34 |
|
| 35 |
-
app.get('/cell/:row/:col/click', logger(), (c) => {
|
| 36 |
const row = Number(c.req.param('row'));
|
| 37 |
const col = Number(c.req.param('col'));
|
| 38 |
if (Number.isNaN(row) || Number.isNaN(col)) return c.text('Invalid coordinates', 400);
|
|
@@ -65,7 +80,7 @@ app.get('/game/status', (c) => {
|
|
| 65 |
return c.body(image);
|
| 66 |
});
|
| 67 |
|
| 68 |
-
app.get('/game/reset', logger(), (c) => {
|
| 69 |
const referer = c.req.header('Referer');
|
| 70 |
let redirectUrl = `https://github.com/${USER}`;
|
| 71 |
if (referer) {
|
|
|
|
| 10 |
|
| 11 |
const app = new Hono();
|
| 12 |
|
| 13 |
+
const customLogger = (message: string, ...rest: string[]) => {
|
| 14 |
+
const timestamp = new Intl.DateTimeFormat('sv-SE', {
|
| 15 |
+
timeZone: 'Asia/Taipei',
|
| 16 |
+
year: 'numeric',
|
| 17 |
+
month: '2-digit',
|
| 18 |
+
day: '2-digit',
|
| 19 |
+
hour: '2-digit',
|
| 20 |
+
minute: '2-digit',
|
| 21 |
+
second: '2-digit',
|
| 22 |
+
hour12: false,
|
| 23 |
+
})
|
| 24 |
+
.format(new Date());
|
| 25 |
+
console.log(`[${timestamp}] ${message}`, ...rest);
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
app.get('/', (c) => c.text(`Play minesweeper:\nhttps://github.com/${USER}`));
|
| 29 |
|
| 30 |
app.get('/headers', (c) => c.text(Array.from(c.req.raw.headers).join('\n')));
|
|
|
|
| 47 |
return c.body(cellImage);
|
| 48 |
});
|
| 49 |
|
| 50 |
+
app.get('/cell/:row/:col/click', logger(customLogger), (c) => {
|
| 51 |
const row = Number(c.req.param('row'));
|
| 52 |
const col = Number(c.req.param('col'));
|
| 53 |
if (Number.isNaN(row) || Number.isNaN(col)) return c.text('Invalid coordinates', 400);
|
|
|
|
| 80 |
return c.body(image);
|
| 81 |
});
|
| 82 |
|
| 83 |
+
app.get('/game/reset', logger(customLogger), (c) => {
|
| 84 |
const referer = c.req.header('Referer');
|
| 85 |
let redirectUrl = `https://github.com/${USER}`;
|
| 86 |
if (referer) {
|