11import { sdk } from './sdk'
2- import { adminPort , homeserverPort , nginxPort } from './utils'
2+ import { adminPort , homeserverPort , mount , nginxPort } from './utils'
33import { homeserverYaml } from './fileModels/homeserver.yml'
4- import { homeserverLogConfig } from './fileModels/homeserver.log.config'
54import * as fs from 'node:fs/promises'
65import { store } from './fileModels/store.json'
76
@@ -13,24 +12,25 @@ export const main = sdk.setupMain(async ({ effects, started }) => {
1312 */
1413 console . info ( '[i] Starting Synapse!' )
1514
16- // Merge to homeserver.yaml to enforce file model protections
17- await homeserverYaml . merge ( effects , { } )
18- await homeserverLogConfig . merge ( effects , { } )
15+ // Read from homeserver.yaml with const() to ensure service restart if the file changes
16+ const config = await homeserverYaml . read ( ) . const ( effects )
17+
18+ if ( ! config ) {
19+ throw new Error ( 'homeserver.yaml not found' )
20+ }
21+
1922 const subcontainer = await sdk . SubContainer . of (
2023 effects ,
2124 { imageId : 'synapse' } ,
22- sdk . Mounts . of ( ) . mountVolume ( {
23- volumeId : 'main' ,
24- subpath : null ,
25- mountpoint : '/data' ,
26- readonly : false ,
27- } ) ,
28- 'synapse' ,
25+ mount ,
26+ 'synapse-sub' ,
2927 )
3028 await subcontainer
3129 . exec ( [ 'chown' , '-R' , '991:991' , '/data' ] )
3230 . then ( ( a ) => a . throw ( ) )
3331
32+ await store . merge ( effects , { serverStarted : true } )
33+
3434 const smtp = await store . read ( ( s ) => s . smtp ) . const ( effects )
3535 if ( smtp ) {
3636 const creds =
@@ -57,9 +57,6 @@ export const main = sdk.setupMain(async ({ effects, started }) => {
5757 }
5858 }
5959
60- // Read from homeserver.yaml with const() to ensure service restart if the file changes
61- const config = await homeserverYaml . read ( ) . const ( effects )
62-
6360 // create and configure nginx container
6461 const nginxContainer = await sdk . SubContainer . of (
6562 effects ,
@@ -80,7 +77,7 @@ server {
8077
8178 location = /.well-known/matrix/server {
8279 default_type application/json;
83- return 200 '{ "m.server": "${ config ? .server_name } :443" }';
80+ return 200 '{ "m.server": "${ config . server_name } :443" }';
8481 }
8582
8683 location / {
@@ -89,7 +86,7 @@ server {
8986
9087 location ~* ^(\/_matrix|\/_synapse\/client|\/_synapse\/admin) {
9188 proxy_pass http://localhost:8008;
92- client_max_body_size 50M; # TODO: make this configurable
89+ client_max_body_size ${ config . max_upload_size } ;
9390 }
9491
9592 error_page 500 502 503 504 /50x.html;
@@ -112,7 +109,7 @@ server {
112109
113110 location = /config.json {
114111 default_type application/json;
115- return 200 '{ "restrictBaseUrl": "https://${ config ? .server_name } " }';
112+ return 200 '{ "restrictBaseUrl": "https://${ config . server_name } " }';
116113 }
117114
118115 error_page 500 502 503 504 /50x.html;
@@ -136,7 +133,7 @@ server {
136133 exec : { command : [ '/start.py' ] } ,
137134 ready : {
138135 display : 'Homeserver' ,
139- gracePeriod : 10000 ,
136+ gracePeriod : 15000 ,
140137 fn : ( ) =>
141138 sdk . healthCheck . checkWebUrl (
142139 effects ,
@@ -165,16 +162,15 @@ server {
165162 . addHealthCheck ( 'admin-interface' , {
166163 ready : {
167164 display : 'Admin Dashboard' ,
168- fn : ( ) => {
169- return sdk . healthCheck . checkWebUrl (
165+ fn : ( ) =>
166+ sdk . healthCheck . checkWebUrl (
170167 effects ,
171168 `http://localhost:${ adminPort } ` ,
172169 {
173170 successMessage : `Running` ,
174171 errorMessage : `Unreachable` ,
175172 } ,
176- )
177- } ,
173+ ) ,
178174 } ,
179175 requires : [ 'nginx' ] ,
180176 } )
0 commit comments