Skip to content

Commit

Permalink
- Reldens - v4.0.0-beta.37 - Missing updates
Browse files Browse the repository at this point in the history
- Merge pull request #255 from damian-pastorini/v4.0.0-beta.37
  • Loading branch information
damian-pastorini authored Jul 23, 2024
2 parents 88e0e35 + 1747cfd commit d3a1973
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion install/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h3 class="form-title">- App -</h3>
</div>
<div class="input-box app-admin-secret">
<label for="app-admin-secret">Admin Panel Secret Key</label>
<input type="text" name="app-admin-secret" id="app-admin-secret" value="{{app-admin-secret}}"/>
<input type="text" name="app-admin-secret" id="app-admin-secret" value="{{app-admin-secret}}" class="required" required/>
</div>
<div class="input-box app-secure-admin">
<label for="app-secure-admin">Secure Admin (login with normal app users)</label>
Expand Down
1 change: 1 addition & 0 deletions lib/admin/server/admin-manager-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AdminManagerConfig extends PropertiesHandler
this.dataServer = serverManager?.dataServer;
this.dataServerConfig = serverManager?.dataServerConfig;
this.gameServer = serverManager?.gameServer;
this.installer = serverManager?.installer;
this.loginManager = serverManager?.loginManager;
this.app = serverManager?.app;
this.applicationFramework = serverManager?.appServerFactory?.applicationFramework;
Expand Down
9 changes: 7 additions & 2 deletions lib/admin/server/admin-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AdminManager
session = null;
broadcastCallback = null;
gameServer = null;
installer = null;
config = null;
themeManager = null;
secret = '';
Expand Down Expand Up @@ -65,6 +66,10 @@ class AdminManager

async setupAdmin()
{
if(!this.installer.isInstalled()){
Logger.info('Reldens is not installed, administration panel will not be available.');
return;
}
this.secret = (process.env.RELDENS_ADMIN_SECRET || '').toString();
this.useSecureLogin = Boolean(Number(process.env.RELDENS_ADMIN_SECURE_LOGIN || 0) || false);
this.rootPath = process.env.RELDENS_ADMIN_ROUTE_PATH || '/reldens-admin';
Expand Down Expand Up @@ -354,9 +359,9 @@ class AdminManager
return driverResource.options.uploadProperties;
}

render(content, params)
async render(content, params)
{
return this.themeManager.templateEngine.render(content, params);
return await this.themeManager.templateEngine.render(content, params);
}

async renderRoute(pageContent, sideBar)
Expand Down
29 changes: 29 additions & 0 deletions lib/game/server/install-templates/data-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "reldens-new-project",
"version": "0.1.0",
"description": "Reldens - New Project",
"main": "index.js",
"scripts": {
"start": "node ."
},
"engines": {
"node": ">=18.0.0",
"npm": ">=8.0.0"
},
"browserslist": [
"> 0.5%, last 2 versions, not dead"
],
"targets": {
"main": false
},
"alias": {
"process": false
},
"dependencies": {
"reldens": "^4.0.0-beta.37"
},
"devDependencies": {
"@reldens/utils": "^0.32.0",
"@colyseus/loadtest": "^0.15.3"
}
}
22 changes: 14 additions & 8 deletions lib/game/server/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Installer
if(fs.existsSync(this.themeManager.installerPathIndex)){
await fs.rmSync(this.themeManager.installerPathIndex, {recursive: true});
}
Logger.info('Re-building installer.');
Logger.info('Building installer...');
await this.themeManager.buildInstaller();
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(
Expand All @@ -58,8 +58,8 @@ class Installer
// Include "secure: true" for that case (that only works through SSL):
// app.use(session({secret: this.secretKey, resave: true, saveUninitialized: true, cookie: {secure: true}}));
app.use(session({secret: this.secretKey, resave: true, saveUninitialized: true}));
app.use((req, res, next) => {
return this.executeForEveryRequest(next, req, res);
app.use(async (req, res, next) => {
return await this.executeForEveryRequest(next, req, res);
});
app.post('/install', async (req, res) => {
return await this.executeInstallProcess(req, res);
Expand All @@ -68,6 +68,9 @@ class Installer

async executeInstallProcess(req, res)
{
if(this.isInstalled()){
return res.redirect('/?redirect=already-installed');
}
let templateVariables = req.body;
this.setCheckboxesMissingValues(templateVariables);
this.setSelectedOptions(templateVariables);
Expand Down Expand Up @@ -117,18 +120,21 @@ class Installer
if('' === templateVariables['app-admin-path']){
templateVariables['app-admin-path'] = '/reldens-admin';
}
if('' === templateVariables['app-admin-secret']){
return res.redirect('/?error=db-installation-process-failed-missing-admin-secret');
}
try {
let envDistTemplate = fs.readFileSync(
this.themeManager.reldensModulePathInstallTemplateEnvDist,
{encoding: this.encoding()}
);
let envFileContent = TemplateEngine.render(envDistTemplate, templateVariables);
let envFileContent = await TemplateEngine.render(envDistTemplate, templateVariables);
fs.writeFileSync(path.join(this.themeManager.projectRoot, '.env'), envFileContent);
let knexDistTemplate = fs.readFileSync(
this.themeManager.reldensModulePathInstallTemplateKnexDist,
{encoding: this.encoding()}
);
let knexFileContent = TemplateEngine.render(knexDistTemplate, templateVariables);
let knexFileContent = await TemplateEngine.render(knexDistTemplate, templateVariables);
fs.writeFileSync(path.join(this.themeManager.projectRoot, 'knexfile.js'), knexFileContent);
fs.writeFileSync(path.join(this.themeManager.projectRoot, 'install.lock'), '');
Logger.info('Installation success!');
Expand All @@ -143,18 +149,18 @@ class Installer
}
}

executeForEveryRequest(next, req, res)
async executeForEveryRequest(next, req, res)
{
if(this.isInstalled()){
return res.sendFile(this.themeManager.installerPathIndex);
return next();
}
if('' === req._parsedUrl.pathname || '/' === req._parsedUrl.pathname){
let installerIndexTemplate = fs.readFileSync(
this.themeManager.installerPathIndex,
{encoding: this.encoding()}
);
let templateVariables = req?.session?.templateVariables || this.fetchDefaults();
return res.send(TemplateEngine.render(installerIndexTemplate, templateVariables));
return res.send(await TemplateEngine.render(installerIndexTemplate, templateVariables));
}
if(!req.url.endsWith('.html')){
return express.static(this.themeManager.installerPath)(req, res, next);
Expand Down

0 comments on commit d3a1973

Please sign in to comment.