generated from openpeeps/pistachio
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example using Tim from Node/Bun JavaScript
Signed-off-by: George Lemon <[email protected]>
- Loading branch information
1 parent
e52cbad
commit 48d0942
Showing
2 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const path = require('path') | ||
const http = require('http') | ||
const tim = require('../bin/tim.node') | ||
|
||
// Tim Engine - Initialize the filesystem | ||
tim.init( | ||
"templates", | ||
"storage", | ||
path.resolve(__dirname), false, 2 | ||
) | ||
|
||
// Tim Engine - Precompile available templates | ||
// exposing some basic data to the global storage | ||
let now = new Date() | ||
tim.precompile({ | ||
year: now.getFullYear(), | ||
stylesheets: [ | ||
{ | ||
type: "stylesheet", | ||
src: "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" | ||
}, | ||
{ | ||
type: "preconnect", | ||
src: "https://fonts.googleapis.com" | ||
}, | ||
{ | ||
type: "preconnect", | ||
src: "https://fonts.gstatic.com" | ||
}, | ||
{ | ||
type: "stylesheet", | ||
src: "https://fonts.googleapis.com/css2?family=Inter:[email protected]&display=swap" | ||
} | ||
] | ||
}) | ||
|
||
// Let's create a simple server using `std/http` module | ||
const | ||
host = 'localhost' | ||
port = '3000' | ||
|
||
http.createServer( | ||
function(req, res) { | ||
res.setHeader('Content-Type', 'text/html') | ||
res.setHeader('charset', 'utf-8') | ||
if(req.url == '/') { | ||
res.writeHead(200) | ||
res.end( | ||
tim.render("index", "base", { | ||
meta: { | ||
title: "Tim Engine is Awesome!" | ||
} | ||
}) | ||
) | ||
} else if(req.url == '/about') { | ||
res.writeHead(200) | ||
res.end( | ||
tim.render("about", "secondary", { | ||
meta: { | ||
title: "Tim Engine is Awesome!" | ||
} | ||
}) | ||
) | ||
} else { | ||
res.writeHead(404) | ||
res.end( | ||
tim.render("error", "base", { | ||
meta: { | ||
title: "Oh, you're a genius!", | ||
msg: "Oh yes, yes. It's got action, it's got drama, it's got dance! Oh, it's going to be a hit hit hit!" | ||
} | ||
}) | ||
) | ||
} | ||
}).listen(port, host, () => { | ||
console.log(`Server is running on http://${host}:${port}`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters