Fix a few things related to running pages and trying to read directories.

main
Zed A. Shaw 9 months ago
parent a43d47fc01
commit 044be2a8c6
  1. 7
      commands/app.js
  2. 2
      knexfile.cjs
  3. 16
      pages/index.html

@ -52,10 +52,11 @@ const configure = async (fastify, opts) => {
app.register(Formbody); app.register(Formbody);
app.get("/*", (req, rep) => { app.get("/*", (req, rep) => {
try {
const target = path.resolve(path.join("pages", req.url)); const target = path.resolve(path.join("pages", req.url));
const index = path.resolve(path.join("pages", req.url, "index.html")); const index = path.resolve(path.join("pages", req.url, "index.html"));
if(fs.existsSync(index)) { if(fs.existsSync(index) && !fs.statSync(index).isDirectory()) {
const result = nunjucks.render(index); const result = nunjucks.render(index);
rep.code(200).type("text/html").send(result); rep.code(200).type("text/html").send(result);
} else if(fs.existsSync(target)) { } else if(fs.existsSync(target)) {
@ -66,6 +67,10 @@ const configure = async (fastify, opts) => {
console.error("404 NOT FOUND", target, "NO INDEX", index); console.error("404 NOT FOUND", target, "NO INDEX", index);
rep.code(404).type("text/html").send("Not Found"); rep.code(404).type("text/html").send("Not Found");
} }
} catch(error) {
console.error(error);
rep.code(500).type("text/html").send("Internal Server Error");
}
}); });
app.register(FastifyStatic, { app.register(FastifyStatic, {

@ -6,7 +6,7 @@ module.exports = {
client: 'sqlite3', client: 'sqlite3',
useNullAsDefault: true, useNullAsDefault: true,
connection: { connection: {
filename: './dev.sqlite3' filename: './db/dev.sqlite3'
} }
}, },

@ -1,16 +1,5 @@
<!doctype html> {% include "./header.html" %}
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<script src="/alpine.js"></script>
<title>Bandolier2</title>
<style> <style>
@import "/open-props.min.css";
@import "/normalize.min.css";
body { body {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -118,5 +107,4 @@ button.primary:hover {
One day I will learn how to run without falling. One day I will learn how to run without falling.
</blockquote> </blockquote>
</section> </section>
</body> {% include "./footer.html" %}
</html>
Loading…
Cancel
Save