Browse Source

Static /files Endpoint; Html static page + Bootstrap CSS

Christian Kahlau 3 years ago
parent
commit
7f00ca3b99

File diff suppressed because it is too large
+ 5 - 0
public/css/bootstrap.min.css


File diff suppressed because it is too large
+ 0 - 0
public/css/bootstrap.min.css.map


+ 24 - 0
public/css/styles.css

@@ -0,0 +1,24 @@
+* {
+  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
+}
+
+.login-form td:first-child {
+  padding-right: 1rem;
+}
+
+.bg-primary {
+  background-color: #394e6b !important;
+}
+
+a {
+  text-decoration: none;
+}
+
+a::before {
+  content: '>';
+  padding-right: 0.5rem;
+}
+
+a.back::before {
+  content: '<';
+}

BIN
public/img/logo_sirius_blau.png


BIN
public/img/logo_sirius_weiss.png


+ 55 - 0
public/index.html

@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <title>Öffentlicher Bereich</title>
+
+    <link rel="stylesheet" href="css/bootstrap.min.css" />
+    <link rel="stylesheet" href="css/styles.css" />
+  </head>
+  <body>
+    <div class="container my-5">
+      <h1>Öffentlicher Bereich</h1>
+      <p>Hier darf jeder auf alles zugreifen.</p>
+
+      <p>Ein paar verlinkte Ressourcen als Beweis:</p>
+      <div class="row mb-4">
+        <div class="col-6">
+          <img class="img-thumbnail bg-light p-5" src="img/logo_sirius_blau.png" />
+        </div>
+        <div class="col-6">
+          <img class="img-thumbnail bg-primary p-5" src="img/logo_sirius_weiss.png" />
+        </div>
+      </div>
+
+      <p>
+        <a href="other.html">Hier geht's noch woanders hin ...</a>
+      </p>
+
+      <h2>Login zum eingeschränkten Bereich</h2>
+      <form method="POST" action="/auth/login" enctype="application/x-www-form-urlencoded" class="login-form">
+        <table border="0" cellpadding="0" cellspacing="0">
+          <tr>
+            <td>Benutzer:</td>
+            <td>
+              <input type="text" name="username" value="testuser" />
+            </td>
+          </tr>
+          <tr>
+            <td>Passwort:</td>
+            <td>
+              <input type="password" name="password" value="pass1234" />
+            </td>
+          </tr>
+          <tr class="login">
+            <td colspan="2">
+              <input type="submit" name="submit" value="Login" />
+            </td>
+          </tr>
+        </table>
+      </form>
+    </div>
+  </body>
+</html>

+ 20 - 0
public/other.html

@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <title>Öffentlicher Bereich - Other</title>
+
+    <link rel="stylesheet" href="css/bootstrap.min.css" />
+    <link rel="stylesheet" href="css/styles.css" />
+  </head>
+  <body>
+    <div class="container my-5">
+      <h1>Öffentlicher Bereich - Other Page</h1>
+      <p>
+        <a class="back" href="index.html">... und hier wieder zurück</a>
+      </p>
+    </div>
+  </body>
+</html>

+ 1 - 1
scripts/init.js

@@ -128,7 +128,7 @@ function readJsonFile(path, encoding = 'utf8') {
         dependencies = Object.keys(pkgJson.devDependencies).join('" "');
         yield exec(`npm install --save-dev "${dependencies}"`, process.stdout, process.stderr);
         console.log(cli.blue('[INFO]'), 'Copying project files...');
-        const copyFiles = ['.env', '.gitignore', '.prettierrc.js', 'tsconfig.json', '.vscode/settings.json', 'src'];
+        const copyFiles = ['.env', '.gitignore', '.prettierrc.js', 'tsconfig.json', '.vscode/settings.json', 'src', 'public'];
         for (const cpFile of copyFiles) {
             const sourceFile = path_1.default.resolve(cloneDir, cpFile);
             const targetFile = path_1.default.resolve(projectRootDir, cpFile);

+ 1 - 1
scripts/init.ts

@@ -116,7 +116,7 @@ async function readJsonFile<T>(path: string, encoding: BufferEncoding = 'utf8'):
     await exec(`npm install --save-dev "${dependencies}"`, process.stdout, process.stderr);
 
     console.log(cli.blue('[INFO]'), 'Copying project files...');
-    const copyFiles = ['.env', '.gitignore', '.prettierrc.js', 'tsconfig.json', '.vscode/settings.json', 'src'];
+    const copyFiles = ['.env', '.gitignore', '.prettierrc.js', 'tsconfig.json', '.vscode/settings.json', 'src', 'public'];
     for (const cpFile of copyFiles) {
       const sourceFile = path.resolve(cloneDir, cpFile);
       const targetFile = path.resolve(projectRootDir, cpFile);

+ 17 - 0
src/webserver.class.ts

@@ -1,5 +1,8 @@
 import express, { Express } from 'express';
 import multiparty from 'multiparty-express';
+import path from 'path';
+
+const PUBLIC_DIR = path.resolve(process.cwd(), 'public');
 
 const multipartMiddleware = multiparty();
 
@@ -42,6 +45,20 @@ export class Webserver {
         });
       });
 
+      /** Serves files in /public via URL /file/~ */
+      this.app.use('/file', express.static(PUBLIC_DIR));
+
+      /** Global Error Handler - transforms exceptions into the right HTTP response */
+      this.app.use((err, req, res, next) => {
+        try {
+          console.error(err);
+          res.status(500).send('INTERNAL SERVER ERROR');
+        } catch (error) {
+          console.error(error);
+          res.status(500).send(error);
+        }
+      });
+
       this.app.listen(port, () => {
         console.log(`Example app listening on http://localhost:${port}`);
       });

Some files were not shown because too many files changed in this diff