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
+22 -23

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. - Factorio game and rcon port now defaults to a random port above 49151.
- Removed unimplemented mods update command. - Removed unimplemented mods update command.
- Fixed rcon password being generated with Math.random(). - 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 ### Breaking Changes
@@ -21,6 +24,8 @@ Version 2.0.0
clusterioModel. clusterioModel.
- Instance names can no longer be invalid Windows file names. - Instance names can no longer be invalid Windows file names.
- Removed config management from the command line and the server manager. - 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 Version 1.2.1
+2 -4
View File
@@ -42,7 +42,6 @@ const authenticate = require("lib/authenticate");
const express = require("express"); const express = require("express");
const compression = require('compression'); const compression = require('compression');
const cookieParser = require('cookie-parser'); const cookieParser = require('cookie-parser');
const ejs = require("ejs");
// Required for express post requests // Required for express post requests
const bodyParser = require("body-parser"); const bodyParser = require("body-parser");
const fileUpload = require('express-fileupload'); const fileUpload = require('express-fileupload');
@@ -59,9 +58,8 @@ app.use(fileUpload());
app.use(compression()); app.use(compression());
// dynamic HTML generations with EJS // dynamic HTML generations with EJS
app.set('views', path.join(__dirname, 'static')); app.set('view engine', 'ejs');
app.set('view engine', 'html'); app.set('views', ['views', 'sharedPlugins']);
app.engine('html', ejs.renderFile);
// give ejs access to some interesting information // give ejs access to some interesting information
app.use(function(req, res, next){ app.use(function(req, res, next){
+3 -7
View File
@@ -69,8 +69,8 @@ class masterPlugin {
let pages = [ let pages = [
{ {
addr: "/serverManager", addr: "/serverManager",
path: path.join(__dirname,"static/index.html"), path: "serverManager/views/index",
render: ejs render: true
}, },
] ]
pages.forEach(page => { pages.forEach(page => {
@@ -81,14 +81,10 @@ class masterPlugin {
} else { } else {
var permissions = {}; var permissions = {};
} }
page.render.renderFile(page.path, { res.render(page.path, {
permissions, permissions,
serverManager: this, serverManager: this,
req: req, req: req,
}, async (err, prom) => {
if(err) console.log(err);
let str = await prom;
res.send(str);
}); });
} else { } else {
res.send(await fs.readFile(page.path)); res.send(await fs.readFile(page.path));
@@ -1,12 +1,12 @@
<!doctype HTML> <!doctype HTML>
<head> <head>
<%- include("./../../../static/head.html") %> <%- include("head") %>
<link rel="stylesheet" type="text/css" href="/serverManager/serverManager.css"> <link rel="stylesheet" type="text/css" href="/serverManager/serverManager.css">
<!-- <script defer type="module" src="/serverManager/index.js"></script> --> <!-- <script defer type="module" src="/serverManager/index.js"></script> -->
</head> </head>
<body> <body>
<%- include("./../../../static/sidebar.html") %> <%- include("sidebar") %>
<div id="body"> <div id="body">
<div id="serverlistDisplayContainer" class="serverManagerMainContainer"> <div id="serverlistDisplayContainer" class="serverManagerMainContainer">
<% <%
@@ -33,6 +33,6 @@
</div> </div>
</div> </div>
<script> <script>
<%- include("./index.js") %> <%- include("serverManager/static/index.js") %>
</script> </script>
</body> </body>
-1
View File
@@ -1 +0,0 @@
<%- include("nav.html") %>
View File
File renamed without changes.
+2 -2
View File
@@ -1,11 +1,11 @@
<!doctype HTML> <!doctype HTML>
<head> <head>
<%- include("head.html") %> <%- include("head") %>
<script defer src="storage.js"></script> <script defer src="storage.js"></script>
</head> </head>
<body> <body>
<%- include("nav.html") %> <%- include("nav") %>
<div id="body" class="container"> <div id="body" class="container">
<div id="storage"> <div id="storage">
<div class="page-header mt-2 row" id="banner"> <div class="page-header mt-2 row" id="banner">
View File
File renamed without changes.
@@ -1,13 +1,13 @@
<!doctype HTML> <!doctype HTML>
<head> <head>
<%- include("head.html") %> <%- include("head") %>
<script src="lib/terminal.js"></script> <script src="lib/terminal.js"></script>
<script src="nodeDetails.js"></script> <script src="nodeDetails.js"></script>
<link rel="stylesheet" type="text/css" href="nodeDetails.css"> <link rel="stylesheet" type="text/css" href="nodeDetails.css">
</head> </head>
<body> <body>
<%- include("nav.html") %> <%- include("nav") %>
<div id="body" class="container"> <div id="body" class="container">
<div id="hero"> <div id="hero">
<div id="display"> <div id="display">
+2 -2
View File
@@ -1,11 +1,11 @@
<!doctype HTML> <!doctype HTML>
<head> <head>
<%- include("head.html") %> <%- include("head") %>
<!-- <script src="slaveDisplay.js"></script> --> <!-- <script src="slaveDisplay.js"></script> -->
</head> </head>
<body> <body>
<%- include("nav.html") %> <%- include("nav") %>
<div id="body" class="container"> <div id="body" class="container">
<div class="page-header mt-2 row" id="banner"> <div class="page-header mt-2 row" id="banner">
<div class="col-lg-8 col-md-7 col-sm-6"> <div class="col-lg-8 col-md-7 col-sm-6">
+2 -2
View File
@@ -1,11 +1,11 @@
<!doctype HTML> <!doctype HTML>
<head> <head>
<%- include("head.html") %> <%- include("head") %>
</head> </head>
<body> <body>
<%- include("nav.html") %> <%- include("nav") %>
<div id="body" class="container"> <div id="body" class="container">
<div class="page-header mt-2 row" id="banner"> <div class="page-header mt-2 row" id="banner">
<div class="row"> <div class="row">
+1
View File
@@ -0,0 +1 @@
<%- include("nav") %>