@@ -28,7 +28,7 @@ export type Application = {
2828 } ;
2929 positionals : string [ ] ;
3030 } ;
31- configuration : {
31+ userConfiguration : {
3232 hostname : string ;
3333 systemAdministratorEmail : string | undefined ;
3434 tls : { key : string ; certificate : string } ;
@@ -37,7 +37,7 @@ export type Application = {
3737 hstsPreload ?: boolean ;
3838 extraCaddyfile ?: string ;
3939 } ;
40- privateConfiguration : {
40+ applicationConfiguration : {
4141 ports : number [ ] ;
4242 } ;
4343 database : Database ;
@@ -98,17 +98,20 @@ application.commandLineArguments = util.parseArgs({
9898 } ,
9999 allowPositionals : true ,
100100} ) as Application [ "commandLineArguments" ] ;
101- application . configuration = (
101+ application . userConfiguration = (
102102 await import ( path . resolve ( application . commandLineArguments . positionals [ 0 ] ) )
103103) . default ;
104- application . configuration . dataDirectory ??= path . resolve ( "./data/" ) ;
105- await fs . mkdir ( application . configuration . dataDirectory , { recursive : true } ) ;
106- application . configuration . environment ??= "production" ;
107- application . privateConfiguration = { } as Application [ "privateConfiguration" ] ;
108- application . privateConfiguration . ports = Array . from (
104+ application . userConfiguration . dataDirectory ??= path . resolve ( "./data/" ) ;
105+ await fs . mkdir ( application . userConfiguration . dataDirectory , {
106+ recursive : true ,
107+ } ) ;
108+ application . userConfiguration . environment ??= "production" ;
109+ application . applicationConfiguration =
110+ { } as Application [ "applicationConfiguration" ] ;
111+ application . applicationConfiguration . ports = Array . from (
109112 {
110113 length :
111- application . configuration . environment === "development"
114+ application . userConfiguration . environment === "development"
112115 ? 1
113116 : os . availableParallelism ( ) ,
114117 } ,
@@ -128,21 +131,24 @@ utilities.log(
128131 application . version ,
129132 "START" ,
130133 application . commandLineArguments . values . type ??
131- `https://${ application . configuration . hostname } ` ,
134+ `https://${ application . userConfiguration . hostname } ` ,
132135 application . commandLineArguments . values . port ?? "" ,
133136) ;
134137process . once ( "beforeExit" , ( ) => {
135138 utilities . log (
136139 "KILL THE NEWSLETTER!" ,
137140 "STOP" ,
138141 application . commandLineArguments . values . type ??
139- `https://${ application . configuration . hostname } ` ,
142+ `https://${ application . userConfiguration . hostname } ` ,
140143 application . commandLineArguments . values . port ?? "" ,
141144 ) ;
142145} ) ;
143146
144147application . database = await new Database (
145- path . join ( application . configuration . dataDirectory , "kill-the-newsletter.db" ) ,
148+ path . join (
149+ application . userConfiguration . dataDirectory ,
150+ "kill-the-newsletter.db" ,
151+ ) ,
146152) . migrate (
147153 sql `
148154 CREATE TABLE "feeds" (
@@ -196,7 +202,7 @@ application.database = await new Database(
196202 ` ,
197203 ) ;
198204
199- if ( application . configuration . environment === "development" ) {
205+ if ( application . userConfiguration . environment === "development" ) {
200206 const feed = database . get < { id : number } > (
201207 sql `
202208 select * from "feeds" where "id" = ${
@@ -333,7 +339,7 @@ if (application.commandLineArguments.values.type === "backgroundJobWorker")
333339 ) ) {
334340 await fs . rm (
335341 path . join (
336- application . configuration . dataDirectory ,
342+ application . userConfiguration . dataDirectory ,
337343 "files" ,
338344 feedEntryEnclosure . publicId ,
339345 ) ,
@@ -565,13 +571,13 @@ application.partials.feed = ({ feed, feedEntries }) =>
565571 <link
566572 rel="self"
567573 href="https://${
568- application . configuration . hostname
574+ application . userConfiguration . hostname
569575 } /feeds/${ feed . publicId } .xml"
570576 />
571577 <link
572578 rel="hub"
573579 href="https://${
574- application . configuration . hostname
580+ application . userConfiguration . hostname
575581 } /feeds/${ feed . publicId } /websub"
576582 />
577583 $${
@@ -599,7 +605,7 @@ application.partials.feed = ({ feed, feedEntries }) =>
599605 rel="alternate"
600606 type="text/html"
601607 href="https://${
602- application . configuration . hostname
608+ application . userConfiguration . hostname
603609 } /feeds/${ feed . publicId } /entries/${ feedEntry . publicId } .html"
604610 />
605611 $${ application . database
@@ -628,7 +634,7 @@ application.partials.feed = ({ feed, feedEntries }) =>
628634 type="${ feedEntryEnclosure . type } "
629635 length="${ String ( feedEntryEnclosure . length ) } "
630636 href="https://${
631- application . configuration . hostname
637+ application . userConfiguration . hostname
632638 } /files/${ feedEntryEnclosure . publicId } /${ feedEntryEnclosure . name } "
633639 />
634640 ` ,
@@ -650,7 +656,7 @@ application.partials.feed = ({ feed, feedEntries }) =>
650656 <small>
651657 <a
652658 href="https://${
653- application . configuration . hostname
659+ application . userConfiguration . hostname
654660 } /feeds/${ feed . publicId } "
655661 >Kill the Newsletter! feed settings</a
656662 >
@@ -866,9 +872,9 @@ application.server?.push({
866872 response . setHeader ( "Content-Type" , "application/json" ) . send (
867873 JSON . stringify ( {
868874 feedId : feed . publicId ,
869- email : `${ feed . publicId } @${ application . configuration . hostname } ` ,
875+ email : `${ feed . publicId } @${ application . userConfiguration . hostname } ` ,
870876 feed : `https://${
871- application . configuration . hostname
877+ application . userConfiguration . hostname
872878 } /feeds/${ feed . publicId } .xml`,
873879 } ) ,
874880 ) ;
@@ -942,7 +948,7 @@ application.server?.push({
942948 <input
943949 type="text"
944950 value="${ request . state . feed . publicId } @${
945- application . configuration . hostname
951+ application . userConfiguration . hostname
946952 } "
947953 readonly
948954 css="${ css `
@@ -960,7 +966,7 @@ application.server?.push({
960966 javascript="${ javascript `
961967 const popover = javascript.popover({ element: this, trigger: "none" });
962968 this.onclick = async () => {
963- await navigator.clipboard.writeText(${ `${ request . state . feed . publicId } @${ application . configuration . hostname } ` } );
969+ await navigator.clipboard.writeText(${ `${ request . state . feed . publicId } @${ application . userConfiguration . hostname } ` } );
964970 popover.showPopover();
965971 await utilities.sleep(1000);
966972 popover.hidePopover();
@@ -987,7 +993,7 @@ application.server?.push({
987993 <input
988994 type="text"
989995 value="https://${
990- application . configuration . hostname
996+ application . userConfiguration . hostname
991997 } /feeds/${ request . state . feed . publicId } .xml"
992998 readonly
993999 css="${ css `
@@ -1006,7 +1012,7 @@ application.server?.push({
10061012 const popover = javascript.popover({ element: this, trigger: "none" });
10071013 this.onclick = async () => {
10081014 await navigator.clipboard.writeText(${ `https://${
1009- application . configuration . hostname
1015+ application . userConfiguration . hostname
10101016 } /feeds/${ request . state . feed . publicId } .xml`} );
10111017 popover.showPopover();
10121018 await utilities.sleep(1000);
@@ -1362,7 +1368,7 @@ application.server?.push({
13621368 request . body [ "hub.mode" ] !== "unsubscribe" ) ||
13631369 request . body [ "hub.topic" ] !==
13641370 `https://${
1365- application . configuration . hostname
1371+ application . userConfiguration . hostname
13661372 } /feeds/${ request . state . feed . publicId } .xml` ||
13671373 typeof request . body [ "hub.callback" ] !== "string" ||
13681374 ( ( ) => {
@@ -1375,7 +1381,7 @@ application.server?.push({
13751381 ( new URL ( request . body [ "hub.callback" ] ) . protocol !== "https:" &&
13761382 new URL ( request . body [ "hub.callback" ] ) . protocol !== "http:" ) ||
13771383 new URL ( request . body [ "hub.callback" ] ) . hostname ===
1378- application . configuration . hostname ||
1384+ application . userConfiguration . hostname ||
13791385 new URL ( request . body [ "hub.callback" ] ) . hostname === "localhost" ||
13801386 new URL ( request . body [ "hub.callback" ] ) . hostname === "127.0.0.1" ||
13811387 ( request . body [ "hub.secret" ] !== undefined &&
@@ -1579,11 +1585,14 @@ application.server?.push({
15791585
15801586if ( application . commandLineArguments . values . type === "email" ) {
15811587 application . email = new SMTPServer ( {
1582- name : application . configuration . hostname ,
1588+ name : application . userConfiguration . hostname ,
15831589 size : 2 ** 19 ,
15841590 disabledCommands : [ "AUTH" ] ,
1585- key : await fs . readFile ( application . configuration . tls . key , "utf-8" ) ,
1586- cert : await fs . readFile ( application . configuration . tls . certificate , "utf-8" ) ,
1591+ key : await fs . readFile ( application . userConfiguration . tls . key , "utf-8" ) ,
1592+ cert : await fs . readFile (
1593+ application . userConfiguration . tls . certificate ,
1594+ "utf-8" ,
1595+ ) ,
15871596 onData : async ( emailStream , session , callback ) => {
15881597 try {
15891598 if (
@@ -1599,12 +1608,12 @@ if (application.commandLineArguments.values.type === "email") {
15991608 throw new Error ( "Invalid ‘mailFrom’." ) ;
16001609 const feeds = session . envelope . rcptTo . flatMap ( ( { address } ) => {
16011610 if (
1602- application . configuration . environment !== "development" &&
1611+ application . userConfiguration . environment !== "development" &&
16031612 address . match ( utilities . emailRegExp ) === null
16041613 )
16051614 return [ ] ;
16061615 const [ feedPublicId , hostname ] = address . split ( "@" ) ;
1607- if ( hostname !== application . configuration . hostname ) return [ ] ;
1616+ if ( hostname !== application . userConfiguration . hostname ) return [ ] ;
16081617 const feed = application . database . get < {
16091618 id : number ;
16101619 publicId : string ;
@@ -1657,15 +1666,15 @@ if (application.commandLineArguments.values.type === "email") {
16571666 ) ! ;
16581667 await fs . mkdir (
16591668 path . join (
1660- application . configuration . dataDirectory ,
1669+ application . userConfiguration . dataDirectory ,
16611670 "files" ,
16621671 feedEntryEnclosure . publicId ,
16631672 ) ,
16641673 { recursive : true } ,
16651674 ) ;
16661675 await fs . writeFile (
16671676 path . join (
1668- application . configuration . dataDirectory ,
1677+ application . userConfiguration . dataDirectory ,
16691678 "files" ,
16701679 feedEntryEnclosure . publicId ,
16711680 feedEntryEnclosure . name ,
@@ -1816,8 +1825,8 @@ if (application.commandLineArguments.values.type === "email") {
18161825 application . email ! . close ( ) ;
18171826 } ) ;
18181827 for ( const file of [
1819- application . configuration . tls . key ,
1820- application . configuration . tls . certificate ,
1828+ application . userConfiguration . tls . key ,
1829+ application . userConfiguration . tls . certificate ,
18211830 ] )
18221831 fsSync
18231832 . watchFile ( file , ( ) => {
@@ -1888,9 +1897,9 @@ if (application.commandLineArguments.values.type === "backgroundJobWorker")
18881897 headers : {
18891898 "Content-Type" : "application/atom+xml; charset=utf-8" ,
18901899 Link : `<https://${
1891- application . configuration . hostname
1900+ application . userConfiguration . hostname
18921901 } /feeds/${ feed . publicId } .xml>; rel="self", <https://${
1893- application . configuration . hostname
1902+ application . userConfiguration . hostname
18941903 } /feeds/${ feed . publicId } /websub>; rel="hub"`,
18951904 ...( typeof feedWebSubSubscription . secret === "string"
18961905 ? {
@@ -1917,7 +1926,7 @@ if (application.commandLineArguments.values.type === "backgroundJobWorker")
19171926 ) ;
19181927
19191928if ( application . commandLineArguments . values . type === undefined ) {
1920- for ( const port of application . privateConfiguration . ports ) {
1929+ for ( const port of application . applicationConfiguration . ports ) {
19211930 node . childProcessKeepAlive ( ( ) =>
19221931 childProcess . spawn (
19231932 process . argv [ 0 ] ,
@@ -1933,7 +1942,7 @@ if (application.commandLineArguments.values.type === undefined) {
19331942 {
19341943 env : {
19351944 ...process . env ,
1936- NODE_ENV : application . configuration . environment ,
1945+ NODE_ENV : application . userConfiguration . environment ,
19371946 } ,
19381947 stdio : "inherit" ,
19391948 } ,
@@ -1954,7 +1963,7 @@ if (application.commandLineArguments.values.type === undefined) {
19541963 {
19551964 env : {
19561965 ...process . env ,
1957- NODE_ENV : application . configuration . environment ,
1966+ NODE_ENV : application . userConfiguration . environment ,
19581967 } ,
19591968 stdio : "inherit" ,
19601969 } ,
@@ -1974,17 +1983,17 @@ if (application.commandLineArguments.values.type === undefined) {
19741983 {
19751984 env : {
19761985 ...process . env ,
1977- NODE_ENV : application . configuration . environment ,
1986+ NODE_ENV : application . userConfiguration . environment ,
19781987 } ,
19791988 stdio : "inherit" ,
19801989 } ,
19811990 ) ,
19821991 ) ;
19831992 caddy . start ( {
1984- ...application . configuration ,
1985- ...application . privateConfiguration ,
1993+ ...application . userConfiguration ,
1994+ ...application . applicationConfiguration ,
19861995 untrustedStaticFilesRoots : [
1987- `/files/* "${ application . configuration . dataDirectory } "` ,
1996+ `/files/* "${ application . userConfiguration . dataDirectory } "` ,
19881997 ] ,
19891998 } ) ;
19901999}
0 commit comments