BlueGit

blue-star tribegen

Files

tribegen / web / index.php

index.php

63fe0a91 History
index.php 2.2 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 } elseif ($apiPath === 'game/events') {
41 include __DIR__ . '/src/api/game.php';
42 } elseif ($apiPath === 'game/sprite') {
43 include __DIR__ . '/src/api/game.php';
44 } elseif ($apiPath === 'game/list') {
45 include __DIR__ . '/src/api/game.php';
46 } elseif ($apiPath === 'game/endMonth') {
47 include __DIR__ . '/src/api/game.php';
48 } elseif ($apiPath === 'game/giveItem') {
49 include __DIR__ . '/src/api/game.php';
50 } elseif ($apiPath === 'game/returnItem') {
51 include __DIR__ . '/src/api/game.php';
52 } elseif ($apiPath === 'game/environments') {
53 include __DIR__ . '/src/api/game.php';
54 } elseif ($apiPath === 'game/cureInjury') {
55 include __DIR__ . '/src/api/game.php';
56 } else {
57 http_response_code(404);
58 echo json_encode(['error' => 'Not found']);
59 }
60} else {
61 // Serve index.html for all other routes (SPA)
62 include __DIR__ . '/indexHtml.html';
63}