fix production-server api calls

pull/8/head
maxime.batista 1 year ago committed by Override-6
parent ff41df4d6b
commit 06abc31067
Signed by untrusted user who does not match committer: maxime.batista
GPG Key ID: 8002CC4B4DD9ECA5

@ -0,0 +1 @@
VITE_API_ENDPOINT=/api

5
.gitignore vendored

@ -1,4 +1,7 @@
.* .vs
.idea
.code
vendor vendor
composer.lock composer.lock

@ -20,7 +20,8 @@ steps:
- curl -L moshell.dev/setup.sh > /tmp/moshell_setup.sh - curl -L moshell.dev/setup.sh > /tmp/moshell_setup.sh
- chmod +x /tmp/moshell_setup.sh - chmod +x /tmp/moshell_setup.sh
- echo n | /tmp/moshell_setup.sh - echo n | /tmp/moshell_setup.sh
- echo "VITE_API_ENDPOINT=/IQBall/$DRONE_BRANCH/public/api" >> .env.PROD
-
- /root/.local/bin/moshell ci/build_react.msh - /root/.local/bin/moshell ci/build_react.msh
- image: composer:latest - image: composer:latest

@ -1,11 +1,10 @@
#!/usr/bin/env moshell #!/usr/bin/env moshell
npm build react
mkdir -p /outputs/public mkdir -p /outputs/public
apt update && apt install jq -y apt update && apt install jq -y
npm install npm install
npm run build -- --base=/IQBall/public npm run build -- --base=/IQBall/public --mode PROD
// Read generated mappings from build // Read generated mappings from build
val result = $(jq -r 'to_entries|map(.key + " " +.value.file)|.[]' dist/manifest.json) val result = $(jq -r 'to_entries|map(.key + " " +.value.file)|.[]' dist/manifest.json)

@ -0,0 +1,4 @@
/**
* This constant defines the API endpoint.
*/
export const API = import.meta.env.VITE_API_ENDPOINT;

@ -1,7 +1,7 @@
import React from "react"; import React from "react";
import "../style/editor.css"; import "../style/editor.css";
import TitleInput from "../components/TitleInput"; import TitleInput from "../components/TitleInput";
import {API} from "../Constants";
export default function Editor({id, name}: { id: number, name: string }) { export default function Editor({id, name}: { id: number, name: string }) {
return ( return (
@ -17,7 +17,7 @@ export default function Editor({id, name}: { id: number, name: string }) {
function update_tactic_name(id: number, new_name: string) { function update_tactic_name(id: number, new_name: string) {
//FIXME avoid absolute path as they would not work on staging server //FIXME avoid absolute path as they would not work on staging server
fetch(`/api/tactic/${id}/edit/name`, { fetch(`${API}/tactic/${id}/edit/name`, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
name: new_name name: new_name

@ -2,7 +2,7 @@
// This file only exists on production servers, and defines the available assets mappings // This file only exists on production servers, and defines the available assets mappings
// in an `ASSETS` array constant. // in an `ASSETS` array constant.
require "../views-mappings.php"; require __DIR__ . "/../views-mappings.php";
const _SUPPORTS_FAST_REFRESH = false; const _SUPPORTS_FAST_REFRESH = false;
$database_file = __DIR__ . "/../database.sqlite"; $database_file = __DIR__ . "/../database.sqlite";

@ -3,6 +3,7 @@
require "../../config.php"; require "../../config.php";
require "../../vendor/autoload.php"; require "../../vendor/autoload.php";
require "../../sql/database.php"; require "../../sql/database.php";
require "../utils.php";
use App\Api\TacticEndpoint; use App\Api\TacticEndpoint;
use App\Connexion; use App\Connexion;
@ -11,7 +12,7 @@ use App\Gateway\TacticInfoGateway;
$con = new Connexion(get_database()); $con = new Connexion(get_database());
$router = new AltoRouter(); $router = new AltoRouter();
$router->setBasePath("/api"); $router->setBasePath(get_public_path() . "/api");
$tacticEndpoint = new TacticEndpoint(new TacticInfoGateway($con)); $tacticEndpoint = new TacticEndpoint(new TacticInfoGateway($con));
$router->map("POST", "/tactic/[i:id]/edit/name", fn(int $id) => $tacticEndpoint->update_name($id)); $router->map("POST", "/tactic/[i:id]/edit/name", fn(int $id) => $tacticEndpoint->update_name($id));

@ -3,6 +3,7 @@
require "../vendor/autoload.php"; require "../vendor/autoload.php";
require "../config.php"; require "../config.php";
require "../sql/database.php"; require "../sql/database.php";
require "utils.php";
use \Twig\Loader\FilesystemLoader; use \Twig\Loader\FilesystemLoader;
use App\Connexion; use App\Connexion;
@ -12,25 +13,11 @@ use App\Controller\EditorController;
use App\Gateway\FormResultGateway; use App\Gateway\FormResultGateway;
use App\Gateway\TacticInfoGateway; use App\Gateway\TacticInfoGateway;
/**
* relative path of the index.php's directory from the server's document root.
*/
function get_base_path() {
// find the server path of the index.php file
$basePath = dirname(substr(__FILE__, strlen($_SERVER['DOCUMENT_ROOT'])));
$c = $basePath[strlen($basePath) - 1];
if ($c == "/" || $c == "\\") {
$basePath = substr($basePath, 0, strlen($basePath) - 1);
}
return $basePath;
}
$loader = new FilesystemLoader('../src/Views/'); $loader = new FilesystemLoader('../src/Views/');
$twig = new \Twig\Environment($loader); $twig = new \Twig\Environment($loader);
$basePath = get_base_path(); $basePath = get_public_path();
$con = new Connexion(get_database()); $con = new Connexion(get_database());
// routes initialization // routes initialization

@ -0,0 +1,16 @@
<?php
/**
* relative path of the public directory from the server's document root.
*/
function get_public_path() {
// find the server path of the index.php file
$basePath = substr(__DIR__, strlen($_SERVER['DOCUMENT_ROOT']));
$c = $basePath[strlen($basePath) - 1];
if ($c == "/" || $c == "\\") {
$basePath = substr($basePath, 0, strlen($basePath) - 1);
}
return $basePath;
}

@ -23,6 +23,7 @@ function resolve_entries(dirname: string): [string, string][] {
export default defineConfig({ export default defineConfig({
root: 'front', root: 'front',
base: '/front', base: '/front',
envDir: '..',
build: { build: {
target: 'es2021', target: 'es2021',
assetsDir: '', assetsDir: '',

Loading…
Cancel
Save