Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 fix + some other minor changes #1

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ RUN npm cache clean --force && \
npm run build && \
rm -rf /root/.npm

FROM busybox:latest AS final
FROM nginx:alpine3.18 AS final

COPY --from=build /app/dist /primal
RUN chown -R nobody:nobody /primal
WORKDIR /usr/share/nginx/html
COPY --from=build /app/dist ./

ADD ./docker_entrypoint.sh /usr/local/bin/docker_entrypoint.sh
RUN chmod a+x /usr/local/bin/docker_entrypoint.sh
168 changes: 167 additions & 1 deletion docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,170 @@

printf "\n\n [i] Starting Primal ...\n\n"

busybox httpd -f -v -p 3000 -h /primal
#
CONF_FILE="/etc/nginx/conf.d/default.conf"
NGINX_CONF='server {
listen 80;
return 301 https://$host$request_uri;
}

server {
listen 8080;
listen 3443 ssl;
http2 on;
ssl_certificate /mnt/cert/main.cert.pem;
ssl_certificate_key /mnt/cert/main.key.pem;

server_name localhost;

root /usr/share/nginx/html;
index index.html index.htm;

# Gzip settings
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_types
application/atom+xml
application/geo+json
application/javascript
application/x-javascript
application/json
application/ld+json
application/manifest+json
application/rdf+xml
application/rss+xml
application/xhtml+xml
application/xml
font/eot
font/otf
font/ttf
image/svg+xml
text/css
text/javascript
text/plain
text/xml;

location / {
try_files $uri $uri/ /index.html;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
'
echo "$NGINX_CONF" > $CONF_FILE

cd /usr/share/nginx/html
cat <<EOF >service-worker.js
// Define the cache name for versioning
const CACHE_NAME = 'primal-pwa-cache-v1';

// Specify the assets to cache
const ASSETS_TO_CACHE = [
'/',
'/index.html',
'/$(ls assets/index-*.js)',
'/$(ls assets/index-*.css)',
'/$(ls assets/favicon-*.ico)',
'/public/fonts.css',
// Add all other assets like images, fonts from the public directory
'/public/Nacelle/Nacelle-Regular.otf',
'/public/RobotoCondensed/RobotoCondensed-Regular.ttf',
// ... other font files and assets
];

self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => cache.addAll(ASSETS_TO_CACHE))
);
});

self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cache => {
if (cache !== CACHE_NAME) {
return caches.delete(cache);
}
})
);
})
);
});

self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
// Serve from cache if available, otherwise fetch from network
return response || fetch(event.request);
})
);
});
EOF

cat << EOF >manifest.json
{
"name": "Primal",
"short_name": "Primal",
"icons": [
{
"src": "public/primal-logo-large.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": ".",
"display": "fullscreen",
"orientation": "portrait"
}
EOF

HTML_FILE="/usr/share/nginx/html/index.html"

# Define the line to insert after
INSERT_AFTER='<\/title>'

# Define the manifest code to insert
INSERT_CODE=' <link rel="manifest" href="manifest.json">'

# Use sed to insert the code
sed -i "s|$INSERT_AFTER|$INSERT_AFTER\n$INSERT_CODE|" $HTML_FILE

# Define the worker code to be injected
CODE=' <script>\
if ('"'"'serviceWorker'"'"' in navigator) {\
window.addEventListener('"'"'load'"'"', function() {\
navigator.serviceWorker.register('"'"'service-worker.js'"'"').then(function(registration) {\
console.log('"'"'ServiceWorker registration successful with scope: '"'"', registration.scope);\
}, function(err) {\
console.log('"'"'ServiceWorker registration failed: '"'"', err);\
});\
});\
}\
</script>'

# Use awk to inject the worker code after the specified line
awk -v code="$CODE" '/lottie-player.js"><\/script>/ { print; print code; next }1' $HTML_FILE > temp.html && mv temp.html $HTML_FILE

_term() {
echo "Caught SIGTERM signal!"
kill -SIGTERM "$primal_process" 2>/dev/null
}

nginx -g 'daemon off;' &
primal_process=$!

trap _term SIGTERM

wait $primal_process
5 changes: 3 additions & 2 deletions instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
4. Choose to **Create Account** or if you already have a Nostr account, click **Login**.
5. Follow the onscreen instructions.

Now, you're all set to explore the Nostr world in a sovereign fashion.
Enjoy! 😊
**Note:** While it's possible to use the Primal web app on your mobile device, we currently recommend using the dedicated mobile app for Android and iOS for a better user experience.

Enjoy exploring the Nostr world in a sovereign fashion! 😊
11 changes: 8 additions & 3 deletions manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: "Primal"
version: 0.93.14
release-notes: "Initial release of Primal for StartOS"
license: MIT
wrapper-repo: "https://github.com/k0gen/primal-startos"
wrapper-repo: "https://github.com/PrimalHQ/primal-startos"
upstream-repo: "https://github.com/PrimalHQ/primal-web-app"
support-site: "https://github.com/PrimalHQ/primal-web-app/issues"
marketing-site: "https://primal.net/"
Expand All @@ -24,6 +24,7 @@ main:
args: []
mounts:
main: /root
cert: /mnt/cert
health-checks:
web-ui:
name: Web UI
Expand All @@ -34,17 +35,21 @@ properties: ~
volumes:
main:
type: data
cert:
type: certificate
interface-id: main
interfaces:
main:
name: User Interface
description: A simple user interface that is expected to display the text "Hello Word"
description: Main user interface for interacting with Primal in a web browser.
tor-config:
port-mapping:
80: "3000"
443: "3443"
lan-config:
443:
ssl: true
internal: 3000
internal: 8080
ui: true
protocols:
- tcp
Expand Down
2 changes: 1 addition & 1 deletion scripts/procedures/healthChecks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { types as T, healthUtil } from "../deps.ts";

export const health: T.ExpectedExports.health = {
"web-ui": healthUtil.checkWebUrl("http://primal.embassy:3000")
"web-ui": healthUtil.checkWebUrl("http://primal.embassy:8080")
}
Loading