BlueGit

blue-star tribegen

Files

tribegen / web / public / index.php

index.php

initial generation
timfa Tim · pushed by timfa · 9 months ago
0b655138 History
index.php 1.4 KiB Download Raw
1<?php
2session_start();
3
4require_once __DIR__ . '/../vendor/autoload.php';
5
6use TribeGen\Database\Database;
7
8// Initialize database if needed
9Database::getInstance()->initializeTables();
10
11// Route the request
12$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
13$path = str_replace('/tribegen', '', $path);
14
15// API routes
16if (strpos($path, '/api/') === 0) {
17 header('Content-Type: application/json');
18
19 $apiPath = substr($path, 5);
20
21 // Auth routes
22 if ($apiPath === 'auth/register') {
23 include __DIR__ . '/../src/api/auth.php';
24 } elseif ($apiPath === 'auth/login') {
25 include __DIR__ . '/../src/api/auth.php';
26 } elseif ($apiPath === 'auth/logout') {
27 include __DIR__ . '/../src/api/auth.php';
28 } elseif ($apiPath === 'game/new') {
29 include __DIR__ . '/../src/api/game.php';
30 } elseif ($apiPath === 'game/load') {
31 include __DIR__ . '/../src/api/game.php';
32 } elseif ($apiPath === 'game/save') {
33 include __DIR__ . '/../src/api/game.php';
34 } elseif ($apiPath === 'game/generation') {
35 include __DIR__ . '/../src/api/game.php';
36 } elseif ($apiPath === 'game/event') {
37 include __DIR__ . '/../src/api/game.php';
38 } else {
39 http_response_code(404);
40 echo json_encode(['error' => 'Not found']);
41 }
42} else {
43 // Serve index.html for all other routes (SPA)
44 include __DIR__ . '/index.html';
45}