counter
This commit is contained in:
3
public/json/wanderers.json
Normal file
3
public/json/wanderers.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"count": 0
|
||||
}
|
||||
17
server.js
17
server.js
@@ -1,5 +1,6 @@
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const fs = require('fs')
|
||||
const bodyParser = require('body-parser');
|
||||
const crypto = require('crypto');
|
||||
const { exec } = require('child_process');
|
||||
@@ -8,6 +9,17 @@ require('dotenv').config();
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
const GITEA_SECRET = process.env.GITEA_SECRET
|
||||
const counterFilePath = path.join(__dirname, 'public/json/wanderers.json');
|
||||
|
||||
function readCounter() {
|
||||
const data = fs.readFileSync(counterFilePath)
|
||||
return JSON.parse(data).count;
|
||||
}
|
||||
|
||||
function writeCounter(count) {
|
||||
const data = JSON.stringify({ count: count}, null, 2)
|
||||
fs.writeFileSync(counterFilePath, data)
|
||||
}
|
||||
|
||||
// Serve static files from the 'public' directory
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
@@ -23,7 +35,10 @@ app.use(bodyParser.json({
|
||||
app.use((req, res, next) => {
|
||||
const urlPath = req.path.split('?')[0];
|
||||
const htmlRoutes = ['/about', '/list', '/gallery'];
|
||||
|
||||
let count = readCounter()
|
||||
count++;
|
||||
writeCounter(count)
|
||||
console.log(count)
|
||||
if (htmlRoutes.includes(urlPath)) {
|
||||
req.url += '.html';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user