Move ejs templates to views/

Move the ejs templates to the default Express.js views/ folder and
change their extension to .ejs.  Reconfigure Express.js to look for
templates in the views folders as well as the plugins folder.  This
enables plugins to render templates using paths of following format
"pluginName/path/to/page-or-view".
This commit is contained in:
Hornwitser committed 2019-09-18 16:54:11 +02:00
1 parent a4983d75fb
commit a62e8d17a3
12 files changed
+27 -28

No files matched your search

+5
View File
@@ -10,6 +10,9 @@ Version 2.0.0
- Factorio game and rcon port now defaults to a random port above 49151.
- Removed unimplemented mods update command.
- Fixed rcon password being generated with Math.random().
- Added plugins directory to the views path. This makes it possible for
plugins to render their own ejs views or pages in their own folders by
using paths of the format "pluginName/path/to/page-or-view".
### Breaking Changes
@@ -21,6 +24,8 @@ Version 2.0.0
clusterioModel.
- Instance names can no longer be invalid Windows file names.
- Removed config management from the command line and the server manager.
- Moved ejs templates into views folder and changed their extension to
.ejs. Breaks playerManager.
Version 1.2.1
+2 -4
View File
@@ -42,7 +42,6 @@ const authenticate = require("lib/authenticate");
const express = require("express");
const compression = require('compression');
const cookieParser = require('cookie-parser');
const ejs = require("ejs");
// Required for express post requests
const bodyParser = require("body-parser");
const fileUpload = require('express-fileupload');
@@ -59,9 +58,8 @@ app.use(fileUpload());
app.use(compression());
// dynamic HTML generations with EJS
app.set('views', path.join(__dirname, 'static'));
app.set('view engine', 'html');
app.engine('html', ejs.renderFile);
app.set('view engine', 'ejs');
app.set('views', ['views', 'sharedPlugins']);
// give ejs access to some interesting information
app.use(function(req, res, next){
+3 -7
View File
@@ -69,8 +69,8 @@ class masterPlugin {
let pages = [
{
addr: "/serverManager",
path: path.join(__dirname,"static/index.html"),
render: ejs
path: "serverManager/views/index",
render: true
},
]
pages.forEach(page => {
@@ -81,14 +81,10 @@ class masterPlugin {
} else {
var permissions = {};
}
page.render.renderFile(page.path, {
res.render(page.path, {
permissions,
serverManager: this,
req: req,
}, async (err, prom) => {
if(err) console.log(err);
let str = await prom;
res.send(str);
});
} else {
res.send(await fs.readFile(page.path));
@@ -1,12 +1,12 @@
<!doctype HTML>
<head>
<%- include("./../../../static/head.html") %>
<%- include("head") %>
<link rel="stylesheet" type="text/css" href="/serverManager/serverManager.css">
<!-- <script defer type="module" src="/serverManager/index.js"></script> -->
</head>
<body>
<%- include("./../../../static/sidebar.html") %>
<%- include("sidebar") %>
<div id="body">
<div id="serverlistDisplayContainer" class="serverManagerMainContainer">
<%
@@ -33,6 +33,6 @@
</div>
</div>
<script>
<%- include("./index.js") %>
<%- include("serverManager/static/index.js") %>
</script>
</body>
-1
View File
@@ -1 +0,0 @@
<%- include("nav.html") %>
View File
File renamed without changes.
+3 -3
View File
@@ -1,11 +1,11 @@
<!doctype HTML>
<head>
<%- include("head.html") %>
<%- include("head") %>
<script defer src="storage.js"></script>
</head>
<body>
<%- include("nav.html") %>
<%- include("nav") %>
<div id="body" class="container">
<div id="storage">
<div class="page-header mt-2 row" id="banner">
@@ -46,4 +46,4 @@
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
</body>
</body>
+1 -1
View File
@@ -34,4 +34,4 @@
<div class="nav-item">
<a class="nav-link align-middle" href="/settings">Settings</a>
</div>
</nav>
</nav>
@@ -1,13 +1,13 @@
<!doctype HTML>
<head>
<%- include("head.html") %>
<%- include("head") %>
<script src="lib/terminal.js"></script>
<script src="nodeDetails.js"></script>
<link rel="stylesheet" type="text/css" href="nodeDetails.css">
</head>
<body>
<%- include("nav.html") %>
<%- include("nav") %>
<div id="body" class="container">
<div id="hero">
<div id="display">
@@ -29,4 +29,4 @@
<!-- JS generates a div called .Terminal that appears here with the display and typing things -->
</div>
</div>
</body>
</body>
+3 -3
View File
@@ -1,11 +1,11 @@
<!doctype HTML>
<head>
<%- include("head.html") %>
<%- include("head") %>
<!-- <script src="slaveDisplay.js"></script> -->
</head>
<body>
<%- include("nav.html") %>
<%- include("nav") %>
<div id="body" class="container">
<div class="page-header mt-2 row" id="banner">
<div class="col-lg-8 col-md-7 col-sm-6">
@@ -59,4 +59,4 @@
<script>
$('.plugin-link a').addClass('btn btn-primary')
</script>
</body>
</body>
+3 -3
View File
@@ -1,11 +1,11 @@
<!doctype HTML>
<head>
<%- include("head.html") %>
<%- include("head") %>
</head>
<body>
<%- include("nav.html") %>
<%- include("nav") %>
<div id="body" class="container">
<div class="page-header mt-2 row" id="banner">
<div class="row">
@@ -16,4 +16,4 @@
</div>
</div>
<script src="settings.js"></script>
</body>
</body>
+1
View File
@@ -0,0 +1 @@
<%- include("nav") %>