46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
const express = require('express');
|
|
const cors = require('cors');
|
|
const https = require('https');
|
|
const fs = require('fs');
|
|
const API_KEY = 'pgqhLFWbDFu4Byz#4afNYX2F6Fa1&$KPjved$8%sUdTQV52caip#EpIKxYUkdd4S'; // 任意のAPIキーを設定
|
|
|
|
const app = express();
|
|
app.use(cors({
|
|
origin: [
|
|
'https://neo999.next-hd.net',
|
|
'https://nextoffice.next-hd.co.jp',
|
|
], // 許可するオリジン
|
|
optionsSuccessStatus: 200
|
|
}));
|
|
|
|
// APIエンドポイント
|
|
app.post('/server', (req, res) => {
|
|
let rawBody = '';
|
|
req.on('data', (chunk) => {
|
|
rawBody += chunk; // リクエストデータをそのまま取得
|
|
});
|
|
|
|
req.on('end', () => {
|
|
// APIキーの検証
|
|
const apiKey = req.headers['x-api-key'];
|
|
if (!apiKey || apiKey !== API_KEY) {
|
|
return res.status(401).json({ error: 'APIキーが不正です' });
|
|
}
|
|
|
|
console.log('Headers:', req.headers); // ヘッダーを出力
|
|
console.log('Raw Body:', rawBody); // パースせずにそのまま出力
|
|
res.json({ message: 'リクエストを受け付けました', rawBody });
|
|
});
|
|
});
|
|
|
|
// HTTPSサーバー起動
|
|
const PORT = 30399;
|
|
const sslOptions = {
|
|
cert: fs.readFileSync('/etc/letsencrypt/live/neo999.next-hd.net/fullchain.pem'),
|
|
key: fs.readFileSync('/etc/letsencrypt/live/neo999.next-hd.net/privkey.pem')
|
|
};
|
|
|
|
https.createServer(sslOptions, app).listen(PORT, () => {
|
|
console.log(`APIサーバー起動: https://neo999.next-hd.net:${PORT}/server`);
|
|
});
|