-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
32 lines (26 loc) · 899 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import cors from 'cors';
import express from 'express';
import path from 'path';
import { fileURLToPath } from 'url';
// ES 모듈에서 __dirname을 구현
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
app.use(express.json());
app.use(cors());
app.use(express.static(path.join(__dirname, 'dist'))); // 여기서 'dist' 디렉토리를 지정해야 합니다.
app.listen(8080, function () {
console.log('listening on 8080!');
});
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
app.get('/getUserIP', (req, res) => {
let userIP = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
if (userIP === '::1' || userIP === '::ffff:127.0.0.1') {
userIP = '203.237.81.62';
// userIP = '125.135.79.166';
console.log(userIP);
}
res.send(userIP);
});