Skip to content

Commit 0ac4eb2

Browse files
authored
Merge pull request #25 from JMCulhane/setup-db-connection
Setup db connection
2 parents 1e48480 + 86d5048 commit 0ac4eb2

25 files changed

+2262
-242
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- setup-db-connection
78
workflow_dispatch:
89

910
jobs:
@@ -29,6 +30,13 @@ jobs:
2930
run: npm run build
3031
working-directory: ./chelle-fulk-main
3132

33+
- name: Create API directory and copy PHP files
34+
run: |
35+
mkdir -p chelle-fulk-main/build/api
36+
cp chelle-fulk-main/api/*.php chelle-fulk-main/build/api/
37+
echo "DB_HOST=${{ secrets.DB_HOST }}" > chelle-fulk-main/build/api/.env
38+
echo "DB_USER=${{ secrets.DB_USER }}" >> chelle-fulk-main/build/api/.env
39+
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> chelle-fulk-main/build/api/.env
3240
3341
- name: Deploy to superb.net via FTP
3442
uses: SamKirkland/FTP-Deploy-Action@v4.3.4

chelle-fulk-main/api/.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DB_HOST=
2+
DB_USER=
3+
DB_PASSWORD=

chelle-fulk-main/api/.htaccess

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<IfModule mod_headers.c>
2+
Header always set Access-Control-Allow-Origin "*"
3+
Header always set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
4+
Header always set Access-Control-Allow-Headers "Content-Type, Authorization, X-Auth-Token"
5+
Header always set Access-Control-Max-Age "3600"
6+
</IfModule>
7+
8+
# Preserve Authorization header for PHP scripts
9+
<IfModule mod_rewrite.c>
10+
RewriteEngine On
11+
12+
# Pass Authorization header to PHP
13+
RewriteCond %{HTTP:Authorization} .
14+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
15+
16+
# Handle preflight OPTIONS requests
17+
RewriteCond %{REQUEST_METHOD} OPTIONS
18+
RewriteRule ^(.*)$ $1 [R=200,L]
19+
</IfModule>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Database Connection Script for superb.net
4+
*
5+
* This script establishes a connection to the MySQL database hosted on superb.net
6+
* using mysqli for secure and modern database interaction.
7+
*/
8+
9+
// Load environment variables from .env file
10+
if (file_exists(__DIR__ . '/.env')) {
11+
$lines = file(__DIR__ . '/.env', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
12+
foreach ($lines as $line) {
13+
if (strpos(trim($line), '#') === 0) continue;
14+
list($key, $value) = explode('=', $line, 2);
15+
putenv(trim($key) . '=' . trim($value));
16+
}
17+
}
18+
19+
// Database configuration - values injected via GitHub Actions during deployment
20+
$db_host = getenv('DB_HOST');
21+
$db_name = getenv('DB_USER');
22+
$db_user = getenv('DB_USER');
23+
$db_pass = getenv('DB_PASSWORD');
24+
25+
// Create connection
26+
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
27+
28+
// Check connection
29+
if ($conn->connect_error) {
30+
die("Connection failed: " . $conn->connect_error);
31+
}
32+
33+
// Set charset to utf8mb4 for full Unicode support
34+
$conn->set_charset("utf8mb4");
35+
36+
// Connection successful
37+
// echo "Connected successfully";
38+
39+
// The $conn variable is now available for database queries
40+
41+
?>

0 commit comments

Comments
 (0)