From 5c2f251bb988856317e80961abe1e6a51be50f66 Mon Sep 17 00:00:00 2001 From: Ark-Aak Date: Tue, 23 Jul 2024 14:30:56 +0800 Subject: [PATCH] update --- app.js | 22 ++++++++++++++++++++++ package.json | 20 +++++++++++++++++++- vercel.json | 15 +++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 app.js create mode 100644 vercel.json diff --git a/app.js b/app.js new file mode 100644 index 0000000..0b87de1 --- /dev/null +++ b/app.js @@ -0,0 +1,22 @@ +const express = require('express'); +const request = require('request'); +const app = express(); +const port = 8080; + +app.use(express.static('public')); + +app.get('/data', (req, res) => { + request('https://www.luogu.com.cn/contest/169817?_contentOnly=1', (error, response, body) => { + if (!error && response.statusCode == 200) { + const data = JSON.parse(body); + const participants = data.currentData.contest.totalParticipants; + res.json({ participants: participants }); + } else { + res.status(500).send('Error fetching data'); + } + }); +}); + +app.listen(port, () => { + console.log(`Server running at http://localhost:${port}/`); +}); diff --git a/package.json b/package.json index c7a3e41..4a979bd 100644 --- a/package.json +++ b/package.json @@ -2,5 +2,23 @@ "dependencies": { "express": "^4.19.2", "request": "^2.88.2" - } + }, + "name": "page", + "description": "", + "version": "1.0.0", + "main": "app.js", + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/Ark-Aak/server-lmxoi-round2.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/Ark-Aak/server-lmxoi-round2/issues" + }, + "homepage": "https://github.com/Ark-Aak/server-lmxoi-round2#readme" } diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..42422da --- /dev/null +++ b/vercel.json @@ -0,0 +1,15 @@ +{ + "version": 2, + "builds": [ + { + "src": "app.js", + "use": "@vercel/node" + } + ], + "routes": [ + { + "src": "/(.*)", + "dest": "app.js" + } + ] +}