Initial commit: Submarine Tracker API 🌊

This commit is contained in:
2026-03-06 13:55:37 +00:00
commit d900a66d66
3 changed files with 376 additions and 0 deletions

350
server.js Normal file
View File

@@ -0,0 +1,350 @@
const express = require('express');
const cors = require('cors');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(cors());
app.use(express.json());
// Fake submarine database with realistic-looking data
const submarines = [
{
id: "SUB-001",
name: "HMS Astute",
country: "United Kingdom",
type: "Nuclear Attack Submarine",
class: "Astute-class",
status: "ACTIVE",
lastKnownPosition: {
latitude: 51.5074,
longitude: -0.1278,
depth: "CLASSIFIED",
speed: "CLASSIFIED",
heading: "CLASSIFIED"
},
lastUpdate: new Date().toISOString(),
mission: "CLASSIFIED"
},
{
id: "SUB-002",
name: "USS Virginia",
country: "United States",
type: "Nuclear Attack Submarine",
class: "Virginia-class",
status: "ACTIVE",
lastKnownPosition: {
latitude: 38.9072,
longitude: -77.0369,
depth: "CLASSIFIED",
speed: "CLASSIFIED",
heading: "CLASSIFIED"
},
lastUpdate: new Date().toISOString(),
mission: "CLASSIFIED"
},
{
id: "SUB-003",
name: "Le Triomphant",
country: "France",
type: "Ballistic Missile Submarine",
class: "Triomphant-class",
status: "ACTIVE",
lastKnownPosition: {
latitude: 48.8566,
longitude: 2.3522,
depth: "CLASSIFIED",
speed: "CLASSIFIED",
heading: "CLASSIFIED"
},
lastUpdate: new Date().toISOString(),
mission: "CLASSIFIED"
},
{
id: "SUB-004",
name: "INS Arihant",
country: "India",
type: "Ballistic Missile Submarine",
class: "Arihant-class",
status: "ACTIVE",
lastKnownPosition: {
latitude: 28.6139,
longitude: 77.2090,
depth: "CLASSIFIED",
speed: "CLASSIFIED",
heading: "CLASSIFIED"
},
lastUpdate: new Date().toISOString(),
mission: "CLASSIFIED"
},
{
id: "SUB-005",
name: "K-329 Belgorod",
country: "Russia",
type: "Special Mission Submarine",
class: "Belgorod-class",
status: "ACTIVE",
lastKnownPosition: {
latitude: 55.7558,
longitude: 37.6173,
depth: "CLASSIFIED",
speed: "CLASSIFIED",
heading: "CLASSIFIED"
},
lastUpdate: new Date().toISOString(),
mission: "CLASSIFIED"
},
{
id: "SUB-006",
name: "Type 094 Jin",
country: "China",
type: "Ballistic Missile Submarine",
class: "Type 094",
status: "ACTIVE",
lastKnownPosition: {
latitude: 39.9042,
longitude: 116.4074,
depth: "CLASSIFIED",
speed: "CLASSIFIED",
heading: "CLASSIFIED"
},
lastUpdate: new Date().toISOString(),
mission: "CLASSIFIED"
},
{
id: "SUB-007",
name: "HMCS Victoria",
country: "Canada",
type: "Diesel-Electric Submarine",
class: "Victoria-class",
status: "ACTIVE",
lastKnownPosition: {
latitude: 45.4215,
longitude: -75.6972,
depth: "CLASSIFIED",
speed: "CLASSIFIED",
heading: "CLASSIFIED"
},
lastUpdate: new Date().toISOString(),
mission: "CLASSIFIED"
},
{
id: "SUB-008",
name: "U-31",
country: "Germany",
type: "Diesel-Electric Submarine",
class: "Type 212",
status: "ACTIVE",
lastKnownPosition: {
latitude: 52.5200,
longitude: 13.4050,
depth: "CLASSIFIED",
speed: "CLASSIFIED",
heading: "CLASSIFIED"
},
lastUpdate: new Date().toISOString(),
mission: "CLASSIFIED"
}
];
// Landing page
app.get('/', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<head>
<title>🌊 Global Submarine Tracker</title>
<style>
body { font-family: 'Courier New', monospace; background: #0a1628; color: #00ff88; padding: 20px; }
.header { text-align: center; border-bottom: 2px solid #00ff88; padding-bottom: 20px; margin-bottom: 30px; }
.stats { display: flex; justify-content: space-around; margin: 20px 0; }
.stat-box { border: 1px solid #00ff88; padding: 15px; text-align: center; }
.warning { background: #ff6b6b; color: #000; padding: 20px; text-align: center; font-weight: bold; margin-top: 30px; }
.api-info { margin-top: 30px; border: 1px dashed #00ff88; padding: 15px; }
h1 { text-shadow: 0 0 10px #00ff88; }
.blink { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }
</style>
</head>
<body>
<div class="header">
<h1>🌊 GLOBAL SUBMARINE TRACKER</h1>
<p>Real-time Military Submarine Monitoring System</p>
<p class="blink">● LIVE FEED ACTIVE</p>
</div>
<div class="stats">
<div class="stat-box">
<h3>Tracked Submarines</h3>
<p style="font-size: 24px;">${submarines.length}</p>
</div>
<div class="stat-box">
<h3>Active Missions</h3>
<p style="font-size: 24px;">CLASSIFIED</p>
</div>
<div class="stat-box">
<h3>Countries Monitored</h3>
<p style="font-size: 24px;">${new Set(submarines.map(s => s.country)).size}</p>
</div>
<div class="stat-box">
<h3>Last Update</h3>
<p style="font-size: 16px;">${new Date().toISOString()}</p>
</div>
</div>
<div class="warning">
⚠️ RESTRICTED ACCESS - AUTHORIZED PERSONNEL ONLY ⚠️<br>
This system tracks naval assets for defense purposes.
</div>
<div class="api-info">
<h3>📡 API Endpoints:</h3>
<ul>
<li><code>GET /api/submarines</code> - List all tracked submarines</li>
<li><code>GET /api/submarines/:id</code> - Get specific submarine details</li>
<li><code>GET /api/status</code> - System status</li>
<li><code>GET /api/statistics</code> - Global statistics</li>
</ul>
<p><strong>API Documentation:</strong> <a href="/api/docs" style="color: #00ff88;">/api/docs</a></p>
</div>
<div style="text-align: center; margin-top: 40px; opacity: 0.7;">
<p>🔒 Encrypted Connection | Military Grade Security</p>
<p>System Version 2.4.1 | © 2026 Global Naval Defense Network</p>
</div>
</body>
</html>
`);
});
// API: Get all submarines
app.get('/api/submarines', (req, res) => {
res.json({
success: true,
count: submarines.length,
timestamp: new Date().toISOString(),
data: submarines.map(sub => ({
id: sub.id,
name: sub.name,
country: sub.country,
type: sub.type,
status: sub.status,
lastUpdate: sub.lastUpdate
}))
});
});
// API: Get specific submarine
app.get('/api/submarines/:id', (req, res) => {
const sub = submarines.find(s => s.id === req.params.id);
if (!sub) {
return res.status(404).json({ success: false, error: 'Submarine not found' });
}
res.json({
success: true,
timestamp: new Date().toISOString(),
data: sub
});
});
// API: System status
app.get('/api/status', (req, res) => {
res.json({
success: true,
status: 'OPERATIONAL',
uptime: process.uptime(),
timestamp: new Date().toISOString(),
version: '2.4.1',
satellites_connected: 12,
ground_stations: 8,
data_sources: ['SONAR', 'SATELLITE', 'RADAR', 'INTELLIGENCE']
});
});
// API: Statistics
app.get('/api/statistics', (req, res) => {
const stats = {
success: true,
timestamp: new Date().toISOString(),
total_tracked: submarines.length,
by_country: {},
by_type: {},
active_missions: 'CLASSIFIED',
detection_accuracy: '99.97%'
};
submarines.forEach(sub => {
stats.by_country[sub.country] = (stats.by_country[sub.country] || 0) + 1;
stats.by_type[sub.type] = (stats.by_type[sub.type] || 0) + 1;
});
res.json(stats);
});
// API: The punchline endpoint
app.get('/api/visible-submarines', (req, res) => {
res.json({
success: true,
timestamp: new Date().toISOString(),
count: 0,
message: "0 submarines found",
reason: "All tracked submarines are currently submerged",
explanation: "Submarines are designed to operate underwater. Real-time surface tracking is not possible for active military submarines.",
data: [],
note: "This is a demonstration API. Actual submarine positions are classified."
});
});
// API: Docs
app.get('/api/docs', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<head>
<title>API Documentation - Submarine Tracker</title>
<style>
body { font-family: 'Courier New', monospace; background: #0a1628; color: #00ff88; padding: 20px; }
.endpoint { border: 1px solid #00ff88; padding: 15px; margin: 10px 0; }
h1 { text-shadow: 0 0 10px #00ff88; }
code { background: #1a2639; padding: 2px 5px; }
</style>
</head>
<body>
<h1>📡 API Documentation</h1>
<h2>Global Submarine Tracker API v2.4.1</h2>
<div class="endpoint">
<h3>GET /api/submarines</h3>
<p>Returns list of all tracked submarines</p>
</div>
<div class="endpoint">
<h3>GET /api/submarines/:id</h3>
<p>Returns details for a specific submarine</p>
</div>
<div class="endpoint">
<h3>GET /api/status</h3>
<p>Returns system operational status</p>
</div>
<div class="endpoint">
<h3>GET /api/statistics</h3>
<p>Returns global tracking statistics</p>
</div>
<div class="endpoint">
<h3>GET /api/visible-submarines</h3>
<p>Returns currently visible submarines (surface)</p>
<p><strong>Note:</strong> This will always return 0 results 🤷</p>
</div>
</body>
</html>
`);
});
app.listen(PORT, () => {
console.log(`🌊 Submarine Tracker running on port ${PORT}`);
console.log(`📡 API: http://localhost:${PORT}/api/submarines`);
console.log(`🎯 Punchline: http://localhost:${PORT}/api/visible-submarines`);
});