BlueGit

blue-star tribegen

Files

tribegen / web / index.php

index.php

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