Skip to content

Commit

Permalink
adding config.js to directus to provide more complex values to enviro…
Browse files Browse the repository at this point in the history
…nment.

Signed-off-by: thanaParis <thana.paris@s44.team>
  • Loading branch information
thanaParis committed Mar 29, 2024
1 parent 2ff16ae commit 2d7c15d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
17 changes: 17 additions & 0 deletions Server/directus-env-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache 2.0

export default function (env) {

const config = {
// API Paths
CITRINEOS_SUBSCRIPTION_API_PATH: '/data/ocpprouter/subscription',
DIRECTUS_CHARGING_STATION_UPDATE_STATUS_PATH: '/charging-stations/update-station-status',
// Environment-specific urls
CITRINEOS_URL: "http://citrine:8080",
DIRECTUS_URL: "http://directus:8055"
}

return config;
}
2 changes: 2 additions & 0 deletions Server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ services:
- 8055:8055
volumes:
- ./data/directus/uploads:/directus/uploads
- ./directus-env-config.js:/directus/config.js
- ../directus-extension-charging-stations-bundle:/directus/extensions/directus-extension-charging-stations-bundle
depends_on:
ocpp-db:
Expand All @@ -70,6 +71,7 @@ services:
SECRET: '0987654321'
ADMIN_EMAIL: 'admin@citrineos.com'
ADMIN_PASSWORD: 'CitrineOS!'
CONFIG_PATH: '/directus/config.js'
DB_CLIENT: 'pg'
DB_HOST: ocpp-db
DB_PORT: 5432
Expand Down
17 changes: 17 additions & 0 deletions Swarm/directus-env-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright Contributors to the CitrineOS Project
//
// SPDX-License-Identifier: Apache 2.0

export default function (env) {

const config = {
// API Paths
CITRINEOS_SUBSCRIPTION_API_PATH: '/data/ocpprouter/subscription',
DIRECTUS_CHARGING_STATION_UPDATE_STATUS_PATH: '/charging-stations/update-station-status',
// Environment-specific urls
CITRINEOS_URL: "http://citrine:8080",
DIRECTUS_URL: "http://directus:8055"
}

return config;
}
6 changes: 4 additions & 2 deletions Swarm/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
timeout: 10s
retries: 3
ocpp-db:
image: citrineos/postgres:preseeded
image: postgis/postgis:latest
ports:
- 5432:5432
volumes:
Expand All @@ -42,12 +42,14 @@ services:
- 8055:8055
volumes:
- ./data/directus/uploads:/directus/uploads
- ./data/directus/extensions:/directus/extensions
- ./directus-env-config.js:/directus/config.js
- ../directus-extension-charging-stations-bundle:/directus/extensions/directus-extension-charging-stations-bundle
environment:
KEY: '1234567890'
SECRET: '0987654321'
ADMIN_EMAIL: 'admin@citrineos.com'
ADMIN_PASSWORD: 'CitrineOS!'
CONFIG_PATH: '/directus/config.js'
DB_CLIENT: 'pg'
DB_HOST: ocpp-db
DB_PORT: 5432
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ export default defineHook(({ action }, { env }) => {

action('ChargingStations.items.create', (input) => {
console.log("Subscribing " + input.key + " to connect and close events");

const stationId = input.key;
const subscriptionUrl = `http://citrine:8080/data/ocpprouter/subscription`;
const updateStationStatusUrl = "http://directus:8055/charging-stations/update-station-status";
const subscriptionUrl = `${env.CITRINEOS_URL}${env.CITRINEOS_SUBSCRIPTION_API_PATH}`;
const updateStationStatusUrl = `${env.DIRECTUS_URL}${env.DIRECTUS_CHARGING_STATION_UPDATE_STATUS_PATH}`;
const requestBody = {
stationId: stationId,
onConnect: true,
onClose: true,
url: updateStationStatusUrl
}

console.log("Subscribing to " + subscriptionUrl + " with request body " + JSON.stringify(requestBody));
fetch(subscriptionUrl, {
method: 'PUT',
headers: {
Expand Down

0 comments on commit 2d7c15d

Please sign in to comment.