change to ejs
This commit is contained in:
parent
9287290479
commit
e92c87c5da
11 changed files with 62 additions and 74 deletions
|
@ -1,12 +1,14 @@
|
|||
import Route from "../route.js";
|
||||
import form from "../comp/form.js";
|
||||
|
||||
// TODO: rewrite
|
||||
let main = new Route([], async function (req, res, input) {
|
||||
return form([
|
||||
{ label: "Username", type: "text", name: "user" },
|
||||
{ label: "Password", type: "password", name: "pass" }
|
||||
],'/api/form/register')
|
||||
return res.render('form', {
|
||||
data: [
|
||||
{ label: "Username", type: "text", name: "user" },
|
||||
{ label: "Password", type: "password", name: "pass" }
|
||||
],
|
||||
'route': '/api/form/login'
|
||||
});
|
||||
});
|
||||
|
||||
export default main;
|
|
@ -1,23 +1,11 @@
|
|||
import Route from "../route.js";
|
||||
import auth from "../form/auth.js";
|
||||
import format from "../common/format.js";
|
||||
|
||||
let main = new Route([auth], async function (req, res, input) {
|
||||
let { username } = input;
|
||||
let cta = (username == '!nobody') ?
|
||||
'<div class="button"><a href="/client/register">Join</a></div>' :
|
||||
'<div class="button"><a href="/client/chat?channel=main">Chat</a></div>';
|
||||
|
||||
return `<div class='area'>
|
||||
<h1>About</h1>
|
||||
<p>
|
||||
<b>BiglyChat</b> is a chat service built on <a href='https://codeberg.org/onezDerv/bigly-chat'>free software</a>.
|
||||
</p>
|
||||
<p>
|
||||
Anyone can selfhost an instance to take control of their community.
|
||||
</p>
|
||||
${cta}
|
||||
</div>`
|
||||
return res.render('main', {
|
||||
username
|
||||
});
|
||||
});
|
||||
|
||||
export default main;
|
|
@ -1,13 +1,15 @@
|
|||
import Route from "../route.js";
|
||||
import form from "../comp/form.js";
|
||||
|
||||
// TODO: rewrite
|
||||
let main = new Route([], async function (req, res, input) {
|
||||
return form([
|
||||
{ label: "Username", type: "text", name: "user" },
|
||||
{ label: "Password", type: "password", name: "pass" },
|
||||
{ label: "Password (again)", type: "password", name: "pass2" },
|
||||
],'/api/form/register')
|
||||
return res.render('form', {
|
||||
data: [
|
||||
{ label: "Username", type: "text", name: "user" },
|
||||
{ label: "Password", type: "password", name: "pass" },
|
||||
{ label: "Password (again)", type: "password", name: "pass2" }
|
||||
],
|
||||
'route': '/api/form/register'
|
||||
});
|
||||
});
|
||||
|
||||
export default main;
|
|
@ -1,18 +0,0 @@
|
|||
const escapeCodes = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
"'": ''',
|
||||
'"': '"'
|
||||
};
|
||||
|
||||
let format = {};
|
||||
|
||||
format.escape = function (str) {
|
||||
return str.replaceAll(
|
||||
/[&<>'"]/g,
|
||||
tag => escapeCodes[tag]
|
||||
)
|
||||
};
|
||||
|
||||
export default format;
|
15
comp/form.js
15
comp/form.js
|
@ -1,15 +0,0 @@
|
|||
function form(elems, action) {
|
||||
elems.push({
|
||||
'label': 'Submit',
|
||||
'type': 'Submit',
|
||||
'name': 'submit'
|
||||
});
|
||||
|
||||
let mapped = elems.map(elem =>
|
||||
`<span class='form-entry'> <span class='form-key'>${elem.label}</span> <input type='${elem.type}' name='${elem.name}'></span>`
|
||||
).join('\n');
|
||||
|
||||
return `<form enctype='multipart/form-data' method='POST' action='${action}'><div class='form-message'></div>${mapped}</form>`
|
||||
}
|
||||
|
||||
export default form;
|
20
index.js
20
index.js
|
@ -2,28 +2,18 @@ import express from 'express';
|
|||
import multer from 'multer';
|
||||
import iterate from './routes.js';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import ejs from "ejs";
|
||||
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
const header = `<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<script src='/static/main.js'></script>
|
||||
<link rel='stylesheet' href='/static/main.css'>
|
||||
</head>
|
||||
<body>
|
||||
`
|
||||
|
||||
const footer = `
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
const app = express();
|
||||
const upload = multer({ dest: 'uploads/' });
|
||||
|
||||
app.use(cookieParser());
|
||||
app.use('/static', express.static('static'));
|
||||
app.engine('.ejs', ejs.__express);
|
||||
app.set('views', './views');
|
||||
app.set('view engine', 'ejs');
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.status(301).redirect('/client/main');
|
||||
|
@ -31,7 +21,7 @@ app.get('/', (req, res) => {
|
|||
|
||||
app.get('/client/:route', async (req, res) => {
|
||||
let dat = await iterate(req, res, 'client');
|
||||
res.send(header + dat + footer);
|
||||
//res.send(dat);
|
||||
})
|
||||
|
||||
app.get('/api/get/:route', async (req, res) => {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
"dependencies": {
|
||||
"bcrypt": "^5.1.1",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"ejs": "^3.1.10",
|
||||
"express": "^4.19.2",
|
||||
"sqlite": "^5.1.1",
|
||||
"sqlite3": "^5.1.7",
|
||||
|
|
2
views/footer.ejs
Normal file
2
views/footer.ejs
Normal file
|
@ -0,0 +1,2 @@
|
|||
</body>
|
||||
</html>
|
11
views/form.ejs
Normal file
11
views/form.ejs
Normal file
|
@ -0,0 +1,11 @@
|
|||
<%- include('header.ejs') -%>
|
||||
<form enctype='multipart/form-data' method='POST' action='<%= route %>'>
|
||||
<div class='form-message'></div>
|
||||
<% for (let elem of data) { %>
|
||||
<span class='form-entry'> <span class='form-key'>
|
||||
<%= elem.label %>
|
||||
</span> <input type='<%= elem.type %>' name='<%= elem.name %>'></span>
|
||||
<% } %>
|
||||
<input type='Submit' name='Submit'>
|
||||
</form>
|
||||
<%- include('footer.ejs') -%>
|
9
views/header.ejs
Normal file
9
views/header.ejs
Normal file
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<script src='/static/main.js'></script>
|
||||
<link rel='stylesheet' href='/static/main.css'>
|
||||
</head>
|
||||
|
||||
<body>
|
16
views/main.ejs
Normal file
16
views/main.ejs
Normal file
|
@ -0,0 +1,16 @@
|
|||
<%- include('header.ejs') -%>
|
||||
<div class='area'>
|
||||
<h1>About</h1>
|
||||
<p>
|
||||
<b>BiglyChat</b> is a project sharing communtiy built on <a href='https://scratch.mit.edu/'>Scratch</a> and
|
||||
<a href='https://turbowarp.org'>TurboWarp</a>
|
||||
. The source code is <a href='https://codeberg.org/onezDerv/bigly-chat'>free software</a>.
|
||||
</p>
|
||||
<p>
|
||||
Anyone can selfhost an instance to take control of their community.
|
||||
</p>
|
||||
<%if (username=='!nobody' ) { %>
|
||||
<div class="button"><a href="/client/register">Join</a></div>
|
||||
<% } %>
|
||||
</div>
|
||||
<%- include('footer.ejs') -%>
|
Loading…
Reference in a new issue