This commit is contained in:
b1ek 2023-03-04 11:09:05 +10:00
commit 83e72e7ed6
Signed by: blek
GPG Key ID: 14546221E3595D0C
9 changed files with 127 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
node_modules
.env
package-lock.json
# code
!*.js
!*.pug
!*.css
!*.md

35
index.js Normal file
View File

@ -0,0 +1,35 @@
require('dotenv').config({});
if (process.env.APP_DEBUG) {
process.env.DEBUG = '*/*';
}
const { APP_PORT } = process.env;
const express = require('express');
const app = express();
const routes = require('./routes');
const middleware = require('./middleware');
app.use(middleware);
app.use(routes);
app.use(express.static('public'));
app.set('view engine', 'pug');
app.set('views', './views');
const server = app.listen(APP_PORT, () => {
console.log('Running on port ' + APP_PORT);
});
function graceful_exit() {
console.log('Exiting...');
server.closeAllConnections();
server.close((err) => {
if (err) console.error(err);
process.exit(0);
})
}
process.on('SIGINT', graceful_exit);
process.on('SIGTERM', graceful_exit);

4
middleware/index.js Normal file
View File

@ -0,0 +1,4 @@
const express = require('express');
const router = express.Router();
module.exports = router;

18
package.json Normal file
View File

@ -0,0 +1,18 @@
{
"name": "blek-bin",
"version": "0.0.1",
"description": "A privacy-respecting, js-free alternative to pastebin",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "node index.js"
},
"author": "b1ek",
"license": "MIT",
"dependencies": {
"dotenv": "^16.0.3",
"express": "^4.18.2",
"express-async-handler": "^1.2.0",
"pug": "^3.0.2"
}
}

19
public/static/main.css Normal file
View File

@ -0,0 +1,19 @@
body {
background-color: antiquewhite;
font-family: monospace;
}
textarea {
background-color: rgb(248, 241, 232);
border: 1px solid #6c6f6c;
border-radius: 4px;
box-shadow: 0 2px 2px #20402030;
padding: 4px 8px
}
textarea:hover {
box-shadow: 0 2px 4px #20402040;
}
.data {
width: 400px;
height: 240px
}

6
routes/index.js Normal file
View File

@ -0,0 +1,6 @@
const express = require('express');
const router = express.Router();
router.use(require('./main'));
module.exports = router;

11
routes/main.js Normal file
View File

@ -0,0 +1,11 @@
const express = require('express');
const router = express.Router();
const handler = require('express-async-handler');
async function index(req, res) {
res.render('main', {maxlen: process.env.MAXLEN});
}
router.get('/', handler(index));
module.exports = router;

8
views/main.pug Normal file
View File

@ -0,0 +1,8 @@
extends template/main.pug
block content
form(action='/upload' method='POST')
p(align='center')
textarea(name='text' class='data' placeholder='Put your text in here!' + (maxlen ? ` (Max length is ${maxlen} bytes)` : ''))
br
input(type='submit' value='Upload!')

17
views/template/main.pug Normal file
View File

@ -0,0 +1,17 @@
block root
doctype html
html(lang='en_US')
head
title blek! Bin#{title ? title : ''}
link(rel='stylesheet' href='/static/main.css')
body
h1(align='center') blek! Bin
p(align='center')
a(href='https://git.blek.codes/blek/bin') Source
| |
a(href='http://blek.codes/project/blek_bin') Project page
hr
block content