Skip to content

Commit 7cf905f

Browse files
committed
allow for local development
1 parent 1fe4375 commit 7cf905f

File tree

9 files changed

+599
-41
lines changed

9 files changed

+599
-41
lines changed

.env.example

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### .env.example
2+
### The following environment variables are useful for connecting to a Unit Test websocket server instance
3+
### In a local development environment, copy this file to .env.development to ensure to connect to local running Unit Test websocket server.
4+
### Set the same value for WS_PORT as in the Liturgical Calendar API project folder.
5+
### For more information, see https://github.com/Liturgical-Calendar/LiturgicalCalendarAPI/blob/development/LitCalTestServer.php
6+
WS_PROTOCOL=ws
7+
WS_HOST=localhost
8+
WS_PORT=8080
9+
API_PROTOCOL=http
10+
API_HOST=localhost
11+
API_PORT=8000 # will not determine on which port the API will launch, only on which port the Unit Test server will look for the API
12+
APP_ENV=development # development | production
13+
# When production, the API will add `/api/{version}` to the path
14+
# where {version} is the version of the API that is automatically detected
15+
# based on the current folder name (dev, v3, v4...).
16+
# When development, no path will be added.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
vendor/
2+
.env
3+
.env.*
4+
!.env.example

.vscode/tasks.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"version": "2.0.0",
3+
"options": {
4+
"env": {
5+
"APP_PROTOCOL": "http",
6+
"APP_HOST": "localhost",
7+
"APP_PORT": "3003"
8+
}
9+
},
10+
"tasks": [
11+
{
12+
"label": "launch-browser",
13+
"type": "shell",
14+
"windows": {
15+
"command": "${command:workbench.action.terminal.sendSequence}",
16+
"args": [
17+
{
18+
"text": "start ${APP_PROTOCOL}://${APP_HOST}:${APP_PORT}\n" // For Windows
19+
}
20+
],
21+
"problemMatcher": []
22+
},
23+
"linux": {
24+
"command": "/bin/bash",
25+
"args": [
26+
"-c",
27+
"if grep -q microsoft /proc/version; then powershell.exe Start-Process ${APP_PROTOCOL}://${APP_HOST}:${APP_PORT}; else xdg-open ${APP_PROTOCOL}://${APP_HOST}:${APP_PORT}; fi"
28+
],
29+
"problemMatcher": []
30+
},
31+
"osx": {
32+
"command": "open ${APP_PROTOCOL}://${APP_HOST}:${APP_PORT}", // For macOS
33+
"problemMatcher": []
34+
}
35+
},
36+
{
37+
"label": "php-server",
38+
"type": "shell",
39+
"command": "php -S ${APP_HOST}:${APP_PORT}",
40+
"group": {
41+
"kind": "build",
42+
"isDefault": true
43+
},
44+
"dependsOn": [
45+
"launch-browser"
46+
]
47+
}
48+
]
49+
}

admin.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717

1818
$ch = curl_init();
1919

20-
if ($apiVersion === 'dev' || $apiVersion === 'v4') {
21-
curl_setopt($ch, CURLOPT_URL, "https://litcal.johnromanodorazio.com/api/$apiVersion/tests");
22-
} else {
23-
curl_setopt($ch, CURLOPT_URL, "https://litcal.johnromanodorazio.com/api/$apiVersion/testsindex/");
24-
}
20+
curl_setopt($ch, CURLOPT_URL, "https://litcal.johnromanodorazio.com/api/$apiVersion/tests");
2521
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
2622
$response = curl_exec($ch);
2723
if (curl_errno($ch)) {

assets/js/index.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,27 @@ const sourceDataChecks = [
7676
*
7777
* @return {void}
7878
*/
79-
const setEndpoints = (ev = null) => {
80-
if(ev !== null) {
81-
ENDPOINTS.VERSION = ev.currentTarget.value;
79+
const setEndpoints = (ev) => {
80+
let API_PATH;
81+
if (APP_ENV==='production') {
82+
if(undefined !== ev) {
83+
ENDPOINTS.VERSION = ev.currentTarget.value;
84+
} else {
85+
ENDPOINTS.VERSION = document.querySelector('#apiVersionsDropdownItems').value;
86+
}
87+
document.querySelector('#admin_url').setAttribute('href', `/admin.php?apiversion=${ENDPOINTS.VERSION}`);
88+
API_PATH = `/api/${ENDPOINTS.VERSION}`;
8289
} else {
83-
ENDPOINTS.VERSION = document.querySelector('#apiVersionsDropdownItems').value;
90+
ENDPOINTS.VERSION = '';
91+
API_PATH = '';
8492
}
85-
console.info('ENDPOINTS.VERSION set to ' + ENDPOINTS.VERSION);
86-
switch(ENDPOINTS.VERSION) {
87-
case 'dev':
88-
case 'v4':
89-
ENDPOINTS.METADATA = `https://litcal.johnromanodorazio.com/api/${ENDPOINTS.VERSION}/calendars`;
90-
ENDPOINTS.TESTSINDEX = `https://litcal.johnromanodorazio.com/api/${ENDPOINTS.VERSION}/tests`;
91-
ENDPOINTS.DECREES = `https://litcal.johnromanodorazio.com/api/${ENDPOINTS.VERSION}/decrees`;
92-
ENDPOINTS.MISSALS = `https://litcal.johnromanodorazio.com/api/${ENDPOINTS.VERSION}/missals`;
93-
break;
94-
case 'v3':
95-
ENDPOINTS.METADATA = `https://litcal.johnromanodorazio.com/api/v3/LitCalMetadata.php`;
96-
ENDPOINTS.TESTSINDEX = `https://litcal.johnromanodorazio.com/api/v3/LitCalTestsIndex.php`;
97-
break;
98-
}
99-
document.querySelector('#admin_url').setAttribute('href', `/admin.php?apiversion=${ENDPOINTS.VERSION}`);
93+
const API_PORT_STR = [443, 80].includes(API_PORT) ? '' : `:${API_PORT}`;
94+
ENDPOINTS.METADATA = `${API_PROTOCOL}://${API_HOST}${API_PORT_STR}${API_PATH}/calendars`;
95+
ENDPOINTS.TESTSINDEX = `${API_PROTOCOL}://${API_HOST}${API_PORT_STR}${API_PATH}/tests`;
96+
ENDPOINTS.DECREES = `${API_PROTOCOL}://${API_HOST}${API_PORT_STR}${API_PATH}/decrees`;
97+
ENDPOINTS.MISSALS = `${API_PROTOCOL}://${API_HOST}${API_PORT_STR}${API_PATH}/missals`;
98+
console.info(`APP_ENV: ${APP_ENV}, API_PATH: ${API_PATH}, API_PROTOCOL: ${API_PROTOCOL}, API_HOST: ${API_HOST}, API_PORT: ${API_PORT}, API_PORT_STR: ${API_PORT_STR}, ENDPOINTS.VERSION: ${ENDPOINTS.VERSION}, ENDPOINTS.METADATA: ${ENDPOINTS.METADATA}, ENDPOINTS.TESTSINDEX: ${ENDPOINTS.TESTSINDEX}, ENDPOINTS.DECREES: ${ENDPOINTS.DECREES}, ENDPOINTS.MISSALS: ${ENDPOINTS.MISSALS}`);
99+
100100
sourceDataChecks[0].sourceFile = ENDPOINTS.METADATA;
101101
sourceDataChecks[5].sourceFile = ENDPOINTS.DECREES;
102102
}
@@ -391,10 +391,12 @@ let currentNationalCalendar = "VA";
391391
let currentCalendarCategory = "nationalcalendar";
392392
let currentResponseType = "JSON";
393393
let currentSourceDataChecks = [];
394+
/**
395+
* The locale variable is defined in footer.php
396+
*/
394397
let countryNames = new Intl.DisplayNames(locale, { type: 'region' } );
395398
let CalendarNations = [];
396399
let selectOptions = {};
397-
//let NationalCalendarsArr = [];
398400
let NationalCalendarTemplates = [ testTemplate( currentSelectedCalendar ) ];
399401
let DiocesanCalendarTemplates = [];
400402
let SpecificUnitTestCategories = [];
@@ -543,7 +545,9 @@ const runTests = () => {
543545
* error occurs, it sets the state to JobsFinished and shows an error toast.
544546
*/
545547
const connectWebSocket = () => {
546-
conn = new WebSocket( 'wss://litcal-test.johnromanodorazio.com' );
548+
console.log( `Connecting to websocket... WS_PROTOCOL: ${WS_PROTOCOL}, WS_HOST: ${WS_HOST}, WS_PORT: ${WS_PORT}` );
549+
const websocketURL = `${WS_PROTOCOL}://${WS_HOST}${[443,80].includes(WS_PORT) ? '' : `:${WS_PORT}`}`;
550+
conn = new WebSocket( websocketURL );
547551

548552
conn.onopen = ( e ) => {
549553
console.log( "Websocket connection established!" );

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"require": {
3-
"liturgical-calendar/components": "^1.0"
3+
"liturgical-calendar/components": "^3.1",
4+
"vlucas/phpdotenv": "^5.6"
45
}
56
}

0 commit comments

Comments
 (0)