@@ -42,7 +42,7 @@ class Installer
4242 if ( fs . existsSync ( this . themeManager . installerPathIndex ) ) {
4343 await fs . rmSync ( this . themeManager . installerPathIndex , { recursive : true } ) ;
4444 }
45- Logger . info ( 'Re-building installer.' ) ;
45+ Logger . info ( 'Building installer.. .' ) ;
4646 await this . themeManager . buildInstaller ( ) ;
4747 app . use ( bodyParser . urlencoded ( { extended : true } ) ) ;
4848 app . use ( express . static (
@@ -58,8 +58,8 @@ class Installer
5858 // Include "secure: true" for that case (that only works through SSL):
5959 // app.use(session({secret: this.secretKey, resave: true, saveUninitialized: true, cookie: {secure: true}}));
6060 app . use ( session ( { secret : this . secretKey , resave : true , saveUninitialized : true } ) ) ;
61- app . use ( ( req , res , next ) => {
62- return this . executeForEveryRequest ( next , req , res ) ;
61+ app . use ( async ( req , res , next ) => {
62+ return await this . executeForEveryRequest ( next , req , res ) ;
6363 } ) ;
6464 app . post ( '/install' , async ( req , res ) => {
6565 return await this . executeInstallProcess ( req , res ) ;
@@ -68,6 +68,9 @@ class Installer
6868
6969 async executeInstallProcess ( req , res )
7070 {
71+ if ( this . isInstalled ( ) ) {
72+ return res . redirect ( '/?redirect=already-installed' ) ;
73+ }
7174 let templateVariables = req . body ;
7275 this . setCheckboxesMissingValues ( templateVariables ) ;
7376 this . setSelectedOptions ( templateVariables ) ;
@@ -117,18 +120,21 @@ class Installer
117120 if ( '' === templateVariables [ 'app-admin-path' ] ) {
118121 templateVariables [ 'app-admin-path' ] = '/reldens-admin' ;
119122 }
123+ if ( '' === templateVariables [ 'app-admin-secret' ] ) {
124+ return res . redirect ( '/?error=db-installation-process-failed-missing-admin-secret' ) ;
125+ }
120126 try {
121127 let envDistTemplate = fs . readFileSync (
122128 this . themeManager . reldensModulePathInstallTemplateEnvDist ,
123129 { encoding : this . encoding ( ) }
124130 ) ;
125- let envFileContent = TemplateEngine . render ( envDistTemplate , templateVariables ) ;
131+ let envFileContent = await TemplateEngine . render ( envDistTemplate , templateVariables ) ;
126132 fs . writeFileSync ( path . join ( this . themeManager . projectRoot , '.env' ) , envFileContent ) ;
127133 let knexDistTemplate = fs . readFileSync (
128134 this . themeManager . reldensModulePathInstallTemplateKnexDist ,
129135 { encoding : this . encoding ( ) }
130136 ) ;
131- let knexFileContent = TemplateEngine . render ( knexDistTemplate , templateVariables ) ;
137+ let knexFileContent = await TemplateEngine . render ( knexDistTemplate , templateVariables ) ;
132138 fs . writeFileSync ( path . join ( this . themeManager . projectRoot , 'knexfile.js' ) , knexFileContent ) ;
133139 fs . writeFileSync ( path . join ( this . themeManager . projectRoot , 'install.lock' ) , '' ) ;
134140 Logger . info ( 'Installation success!' ) ;
@@ -143,18 +149,18 @@ class Installer
143149 }
144150 }
145151
146- executeForEveryRequest ( next , req , res )
152+ async executeForEveryRequest ( next , req , res )
147153 {
148154 if ( this . isInstalled ( ) ) {
149- return res . sendFile ( this . themeManager . installerPathIndex ) ;
155+ return next ( ) ;
150156 }
151157 if ( '' === req . _parsedUrl . pathname || '/' === req . _parsedUrl . pathname ) {
152158 let installerIndexTemplate = fs . readFileSync (
153159 this . themeManager . installerPathIndex ,
154160 { encoding : this . encoding ( ) }
155161 ) ;
156162 let templateVariables = req ?. session ?. templateVariables || this . fetchDefaults ( ) ;
157- return res . send ( TemplateEngine . render ( installerIndexTemplate , templateVariables ) ) ;
163+ return res . send ( await TemplateEngine . render ( installerIndexTemplate , templateVariables ) ) ;
158164 }
159165 if ( ! req . url . endsWith ( '.html' ) ) {
160166 return express . static ( this . themeManager . installerPath ) ( req , res , next ) ;
0 commit comments