|
|
@ -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, { |
|
|
|