Elffuss BraidHub

utopia-ia/elffuss-code public

16e1b35e41ba · 2.8 KiBRawPermalink
1# nginx for the level 2 extension sandbox of Elffuss Code, on x2.utopiaia.com:
2# another registrable domain than code.elffuss.com (web/js/ext2/config.js and
3# sandbox/x2/headers.json name this origin; deploy-sandbox.sh refuses any
4# other). Its folder is /var/www/x2.utopiaia.com, the one deploy-sandbox.sh
5# fills, owned by the user that deploys. Generate the two header snippets with
6#
7# node sandbox/x2/headers.mjs --nginx
8#
9# and save them as /etc/nginx/snippets/x2-sandbox.conf and x2-exthost.conf.
10# Order (README, "Extensions that run code"): main's deploy.sh protecting
11# vendor/x2/ first (deploy-vendor.sh refuses until it does), x2.utopiaia.com
12# resolving to the server that serves Code and its certificate, this vhost
13# and Code's vendor location (at the end of this file), nginx -t and reload,
14# deploy-sandbox.sh, deploy-vendor.sh, and deploy.sh last: it publishes
15# config.js naming this sandbox, and refuses while the server lacks the bundle
16# the manifest names.
17
18server {
19 listen 443 ssl http2;
20 server_name x2.utopiaia.com;
21 ssl_certificate /etc/letsencrypt/live/x2.utopiaia.com/fullchain.pem;
22 ssl_certificate_key /etc/letsencrypt/live/x2.utopiaia.com/privkey.pem;
23 root /var/www/x2.utopiaia.com;
24 access_log off; # the sandbox keeps no log of who loaded it
25 autoindex off;
26 server_tokens off;
27
28 # the sandbox document: only with no query string at all
29 location = /x2/v1/sandbox.html {
30 if ($args != "") { return 404; }
31 include snippets/x2-sandbox.conf;
32 try_files $uri =404;
33 }
34
35 # the extension-host document: only the exact query the library builds
36 location = /x2/v1/exthost-iframe.html {
37 if ($args !~ "^parentOrigin=https%3A%2F%2Fx2\.utopiaia\.com&vscodeWebWorkerExtHostId=[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$") { return 404; }
38 include snippets/x2-exthost.conf;
39 try_files $uri =404;
40 }
41
42 # nothing else exists on this host
43 location / { return 404; }
44}
45
46server {
47 listen 80;
48 server_name x2.utopiaia.com;
49 access_log off;
50 return 301 https://$host$request_uri;
51}
52
53# In the server block of Code (code.elffuss.com), for the verified vendor
54# bundle that deploy-vendor.sh uploads (never compressed again on the way, so
55# the browser checks the exact bytes of the manifest):
56#
57# location ^~ /vendor/x2/ {
58# default_type application/octet-stream;
59# gzip off;
60# add_header Cache-Control "public, max-age=31536000, immutable";
61# add_header X-Content-Type-Options nosniff always;
62# }
63#
64# No `always` on Cache-Control: nginx then adds it only to successful
65# responses. With `always`, a 404 for a build that is not there yet would be
66# cached as immutable for a year, and since the buildId is a content hash,
67# uploading the same bytes later would not help those browsers.
68#
69# Code's host must never serve /x2/ (the sandbox documents live outside web/,
70# so deploy.sh never uploads them).