Skip to content
This repository was archived by the owner on Mar 8, 2025. It is now read-only.

Commit

Permalink
Serve front office config from Nginx.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibz committed Mar 12, 2024
1 parent 817862c commit 6aca7a2
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 27 deletions.
1 change: 0 additions & 1 deletion README.dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,4 @@ Give a look to the `getChannelIdForStall` function to know how we're generating

## Keys used in the code

* `VITE_NOSTR_MARKET_SQUARE_CHANNEL_ID` - Nostr channel id of the Market Square for each community
* `VITE_NOSTR_PM_STALL_PUBLIC_KEY` - Nostr public key of Plebeian Market's market stall
3 changes: 2 additions & 1 deletion services/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM nginx:1.25-alpine-slim

RUN rm /etc/nginx/conf.d/default.conf
RUN mkdir /front-office-config && rm /etc/nginx/conf.d/default.conf
COPY ./web/frontoffice/static/config-pm.json /front-office-config/config.json
COPY ./services/nginx/nginx.conf /etc/nginx/conf.d/nginx.conf

EXPOSE 80
4 changes: 4 additions & 0 deletions services/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ server {
alias /media/;
}

location /front-office-config {
alias /front-office-config/;
}

location / {
add_header Access-Control-Allow-Origin *;
root /front-office-app;
Expand Down
2 changes: 0 additions & 2 deletions web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ COPY ./web /web

COPY ./install.sh /web/frontoffice/static/

RUN mv /web/frontoffice/static/config-pm.json /web/frontoffice/static/config.json

RUN cd /web/shared \
&& npm install

Expand Down
1 change: 0 additions & 1 deletion web/backoffice/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
VITE_TWITTER_USER=@PlebeianMarket
VITE_PM_DESCRIPTION="Self-sovereign marketplace built on Bitcoin and Lightning"
VITE_SITE_NAME="Plebeian Market"
VITE_NOSTR_MARKET_SQUARE_CHANNEL_ID="4211fc228be5af10923f56e60b1b11b8e63bf0ac7dbd3e1e3d767392fdaed4a9"
1 change: 0 additions & 1 deletion web/backoffice/.env.production
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
VITE_BASE_URL=${WWW_BASE_URL}/
VITE_API_BASE_URL=${API_BASE_URL}/
VITE_NOSTR_MARKET_SQUARE_CHANNEL_ID="dd7aee9576b3d85287c37808cec29260d1a97e83bee4f15153d52851ff7db719"
1 change: 0 additions & 1 deletion web/frontoffice/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
VITE_TWITTER_USER=@PlebeianMarket
VITE_PM_DESCRIPTION="Self-sovereign marketplace built on Bitcoin and Lightning"
VITE_SITE_NAME="Plebeian Market"
VITE_NOSTR_MARKET_SQUARE_CHANNEL_ID="4211fc228be5af10923f56e60b1b11b8e63bf0ac7dbd3e1e3d767392fdaed4a9"
VITE_NOSTR_PM_STALL_PUBLIC_KEY="76cc29acb8008c68b105cf655d34de0b1f7bc0215eaae6bbc83173d6d3f7b987"
1 change: 0 additions & 1 deletion web/frontoffice/.env.production
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
VITE_BASE_URL=${WWW_BASE_URL}/
VITE_API_BASE_URL=${API_BASE_URL}/
VITE_NOSTR_MARKET_SQUARE_CHANNEL_ID="dd7aee9576b3d85287c37808cec29260d1a97e83bee4f15153d52851ff7db719"
VITE_NOSTR_PM_STALL_PUBLIC_KEY="28c62ad00fe085a7b2b54a05fdf333367e3e6a4d9650ad1c159f964705b76928"
19 changes: 7 additions & 12 deletions web/frontoffice/src/lib/components/nostr/Button.svelte
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
<script lang="ts">
import { sendMessage } from "$sharedLib/services/nostr";
import { getChannelIdForStallOwner, pmChannelNostrRoomId } from '$sharedLib/nostr/utils'
import { getMarketSquareChannelId } from '$sharedLib/nostr/utils'
import { Info } from "$lib/stores";
export let pmURL: string | null;
let nostrRoomId;
let nostrRoomId: string | null;
let message: string;
let textConfirmationVisible: boolean;
function getNostrTextModal(location: 'stall' | 'mktSquare' | 'nostrFeed') {
async function getNostrTextModal(location: 'mktSquare' | 'nostrFeed') {
switch (location) {
case 'stall':
message = 'Hi people! I just listed a new product. Give it a look:';
// nostrRoomId = getChannelIdForStallOwner($user);
break;
case 'mktSquare':
message = 'Hey! Check the new product I just listed!';
nostrRoomId = pmChannelNostrRoomId;
nostrRoomId = await getMarketSquareChannelId();
break;
case 'nostrFeed':
message = 'Check the product I just published at Plebeian Market!';
nostrRoomId = false;
nostrRoomId = null;
break;
}
Expand Down Expand Up @@ -86,9 +82,8 @@
Share on Nostr
</label>
<ul tabindex="0" class="dropdown-content menu p-2 shadow bg-secondary rounded-box w-72">
<li><a href="#anchorId" on:click|preventDefault={() => getNostrTextModal("stall")}>My Stall</a></li>
<li><a href="#anchorId" on:click|preventDefault={() => getNostrTextModal("mktSquare")}>Market Square</a></li>
<li><a href="#anchorId" on:click|preventDefault={() => getNostrTextModal("nostrFeed")}>Public Nostr</a></li>
<li><a href="#anchorId" on:click|preventDefault={async () => await getNostrTextModal("mktSquare")}>Market Square</a></li>
<li><a href="#anchorId" on:click|preventDefault={async () => await getNostrTextModal("nostrFeed")}>Public Nostr</a></li>
</ul>
</div>

Expand Down
13 changes: 11 additions & 2 deletions web/frontoffice/src/routes/marketsquare/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<script lang="ts">
import { onMount } from 'svelte';
import NostrChat from "$lib/components/nostr/Chat.svelte";
import { pmChannelNostrRoomId } from "$sharedLib/nostr/utils"
import { getMarketSquareChannelId } from "$sharedLib/nostr/utils"
import Titleh1 from "$sharedLib/components/layout/Title-h1.svelte";
let nostrRoomId: string | null = null;
onMount(async () => {
nostrRoomId = await getMarketSquareChannelId();
});
</script>

<svelte:head>
Expand All @@ -10,4 +17,6 @@

<Titleh1>Market Square</Titleh1>

<NostrChat messageLimit={75} nostrRoomId={pmChannelNostrRoomId} isMarketSquare={true} />
{#if nostrRoomId !== null}
<NostrChat messageLimit={75} {nostrRoomId} isMarketSquare={true} />
{/if}
3 changes: 2 additions & 1 deletion web/frontoffice/static/config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
""
],
"homepage_banner_image": "",
"backend_present": false
"backend_present": false,
"market_square_channel_id": ""
}
3 changes: 2 additions & 1 deletion web/frontoffice/static/config-pm.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"03b5036dc3db82604307c1964d2b926417a91c3b11ef75ba6ca55019e9b7a62a"
],
"homepage_banner_image": "",
"backend_present": true
"backend_present": true,
"market_square_channel_id": "dd7aee9576b3d85287c37808cec29260d1a97e83bee4f15153d52851ff7db719"
}
10 changes: 8 additions & 2 deletions web/shared/src/lib/nostr/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import {getEventHash, nip05, nip19, Kind, getSignature, getPublicKey} from "nost
import {goto} from "$app/navigation";
import {get} from "svelte/store";
import {NostrPrivateKey, NostrPublicKey, NostrLoginMethod, stalls, token, Error} from "$sharedLib/stores";
import {getApiBaseUrl, isStaging, isDevelopment} from "$sharedLib/utils";
import {getApiBaseUrl, isStaging, getConfigurationFromFile} from "$sharedLib/utils";
import {sendPrivateMessage} from "$sharedLib/services/nostr";
import { v4 as uuidv4 } from "uuid";

export const pmChannelNostrRoomId = import.meta.env.VITE_NOSTR_MARKET_SQUARE_CHANNEL_ID;
export async function getMarketSquareChannelId() {
let configJson = await getConfigurationFromFile();
if (configJson) {
return configJson['market_square_channel_id'];
}
}

export const pmStallPubkey = import.meta.env.VITE_NOSTR_PM_STALL_PUBLIC_KEY;

// NB: keep in sync with `api/config.py`
Expand Down
2 changes: 1 addition & 1 deletion web/shared/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function getMonthName(month: number) {
}

export async function getConfigurationFromFile() {
let response = await fetch('/config.json')
let response = await fetch('/front-office-config/config.json')

if (!response.ok) {
return false;
Expand Down

0 comments on commit 6aca7a2

Please sign in to comment.