initial work on client-side templating
parent
99879fd91e
commit
57d0b0f856
|
@ -9,7 +9,8 @@
|
||||||
"cli": "ts-node src/cli.ts",
|
"cli": "ts-node src/cli.ts",
|
||||||
"setup": "sh install/setup.sh",
|
"setup": "sh install/setup.sh",
|
||||||
"migrate": "ts-node src/migrate.ts",
|
"migrate": "ts-node src/migrate.ts",
|
||||||
"invite": "ts-node src/cli.ts --invite"
|
"invite": "ts-node src/cli.ts --invite",
|
||||||
|
"make-templates": "cp node_modules/nunjucks/browser/nunjucks-slim.js site &&nunjucks-precompile -i [\"\\.html$\",\"\\.njk$\"] templates > site/templates.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<head>
|
||||||
|
<script src="/nunjucks-slim.js"></script>
|
||||||
|
<script src="/templates.js"></script>
|
||||||
|
<script>
|
||||||
|
nunjucks.configure({ autoescape: true });
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body onload="render()">
|
||||||
|
<script>
|
||||||
|
function render(){
|
||||||
|
switch(window.location.pathname){
|
||||||
|
case "/about.html":
|
||||||
|
document.body.innerHTML = nunjucks.render('about.html');
|
||||||
|
break;
|
||||||
|
case "/tos.html":
|
||||||
|
document.body.innerHTML = nunjucks.render('tos.html');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
document.body.innerHTML = nunjucks.render('404.njk');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function getContext(){
|
||||||
|
var conf = {
|
||||||
|
sitename: "",
|
||||||
|
domain: "",
|
||||||
|
email: "",
|
||||||
|
version: "",
|
||||||
|
registration: false
|
||||||
|
}
|
||||||
|
var info = new XMLHttpRequest();
|
||||||
|
info.onload = () => {
|
||||||
|
if(xhr.status === 200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
|
@ -56,11 +56,12 @@ async function init(){
|
||||||
}
|
}
|
||||||
app.disable('x-powered-by');
|
app.disable('x-powered-by');
|
||||||
//site handlers
|
//site handlers
|
||||||
await initSite(config['satyr']['registration']);
|
//await initSite(config['satyr']['registration']);
|
||||||
//api handlers
|
//api handlers
|
||||||
await initAPI();
|
await initAPI();
|
||||||
//static files if nothing else matches first
|
//static files if nothing else matches first
|
||||||
app.use(express.static(config['http']['directory']));
|
app.use(express.static(config['http']['directory']));
|
||||||
|
await initFE();
|
||||||
//404 Handler
|
//404 Handler
|
||||||
app.use(function (req, res, next) {
|
app.use(function (req, res, next) {
|
||||||
if(tryDecode(req.cookies.Authorization)) {
|
if(tryDecode(req.cookies.Authorization)) {
|
||||||
|
@ -73,6 +74,12 @@ async function init(){
|
||||||
server.listen(config['http']['port']);
|
server.listen(config['http']['port']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function initFE(){
|
||||||
|
app.get('*', (req, res) => {
|
||||||
|
res.sendFile(process.cwd()+'/'+config['http']['directory']+'/index.html');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function newNick(socket, skip?: boolean, i?: number) {
|
async function newNick(socket, skip?: boolean, i?: number) {
|
||||||
if(socket.handshake.headers['cookie'] && !skip){
|
if(socket.handshake.headers['cookie'] && !skip){
|
||||||
let c = await parseCookie(socket.handshake.headers['cookie']);
|
let c = await parseCookie(socket.handshake.headers['cookie']);
|
||||||
|
|
Reference in New Issue