|
@ -1,5 +1,6 @@ |
|
|
const express = require('express'); |
|
|
const express = require('express'); |
|
|
const path = require('path'); |
|
|
const path = require('path'); |
|
|
|
|
|
const fs = require('fs') |
|
|
const bodyParser = require('body-parser'); |
|
|
const bodyParser = require('body-parser'); |
|
|
const crypto = require('crypto'); |
|
|
const crypto = require('crypto'); |
|
|
const { exec } = require('child_process'); |
|
|
const { exec } = require('child_process'); |
|
@ -8,6 +9,17 @@ require('dotenv').config(); |
|
|
const app = express(); |
|
|
const app = express(); |
|
|
const PORT = process.env.PORT || 3000; |
|
|
const PORT = process.env.PORT || 3000; |
|
|
const GITEA_SECRET = process.env.GITEA_SECRET |
|
|
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
|
|
|
// Serve static files from the 'public' directory
|
|
|
app.use(express.static(path.join(__dirname, 'public'))); |
|
|
app.use(express.static(path.join(__dirname, 'public'))); |
|
@ -23,7 +35,10 @@ app.use(bodyParser.json({ |
|
|
app.use((req, res, next) => { |
|
|
app.use((req, res, next) => { |
|
|
const urlPath = req.path.split('?')[0]; |
|
|
const urlPath = req.path.split('?')[0]; |
|
|
const htmlRoutes = ['/about', '/list', '/gallery']; |
|
|
const htmlRoutes = ['/about', '/list', '/gallery']; |
|
|
|
|
|
let count = readCounter() |
|
|
|
|
|
count++; |
|
|
|
|
|
writeCounter(count) |
|
|
|
|
|
console.log(count) |
|
|
if (htmlRoutes.includes(urlPath)) { |
|
|
if (htmlRoutes.includes(urlPath)) { |
|
|
req.url += '.html'; |
|
|
req.url += '.html'; |
|
|
} |
|
|
} |
|
|