1
0
Fork 0

refactor: modularize assets (#22)

* chore(dev):  add nodemon for better DX

* refactor: remove depricated bodyparser

* refactor: remove express-session warnings

* refactor: modularize assets

* refactor: modularize assets
pull/24/head
mak 2022-02-16 16:58:24 +05:30 committed by GitHub
parent 249344bd03
commit a467aa84c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 36 deletions

31
assets/index.js Normal file
View File

@ -0,0 +1,31 @@
const assets = [
{
path: 'bootstrap',
modulePath: 'bootstrap/dist',
},
{
path: 'jquery',
modulePath: 'jquery/dist',
},
{
path: 'octicons',
modulePath: '@primer/octicons/build',
},
{
path: 'filesize',
modulePath: 'filesize/lib',
}, {
path: 'xterm',
modulePath: 'xterm',
}, {
path: 'xterm-addon-attach',
modulePath: 'xterm-addon-attach',
}, {
path: 'xterm-addon-fit',
modulePath: 'xterm-addon-fit',
}
];
module.exports = assets;

View File

@ -6,12 +6,11 @@
const express = require("express");
const { engine: hbs } = require("express-handlebars");
const bodyparser = require("body-parser");
const session = require("express-session");
const busboy = require("connect-busboy");
const flash = require("connect-flash");
const querystring = require("querystring");
const assets = require("./assets");
const archiver = require("archiver");
const notp = require("notp");
@ -73,44 +72,27 @@ app.engine(
app.set("view engine", "handlebars");
app.use("/@assets", express.static(path.join(__dirname, "assets")));
app.use(
"/@assets/bootstrap",
express.static(path.join(__dirname, "node_modules/bootstrap/dist"))
);
app.use(
"/@assets/octicons",
express.static(path.join(__dirname, "node_modules/@primer/octicons/build"))
);
app.use(
"/@assets/jquery",
express.static(path.join(__dirname, "node_modules/jquery/dist"))
);
app.use(
"/@assets/filesize",
express.static(path.join(__dirname, "node_modules/filesize/lib"))
);
app.use(
"/@assets/xterm",
express.static(path.join(__dirname, "node_modules/xterm"))
);
app.use(
"/@assets/xterm-addon-attach",
express.static(path.join(__dirname, "node_modules/xterm-addon-attach"))
);
app.use(
"/@assets/xterm-addon-fit",
express.static(path.join(__dirname, "node_modules/xterm-addon-fit"))
);
// init assets
assets.forEach(asset => {
const { path: url, modulePath } = asset;
app.use(
`/@assets/${url}`,
express.static(path.join(__dirname, `node_modules/${modulePath}`))
);
})
app.use(
session({
secret: process.env.SESSION_KEY || "meowmeow",
resave: false,
saveUninitialized: false
})
);
app.use(flash());
app.use(busboy());
app.use(bodyparser.urlencoded());
app.use(express.urlencoded({
extended: false
}));
// AUTH
const KEY = process.env.KEY
@ -403,7 +385,7 @@ app.get("/*@download", (req, res) => {
let files = null;
try {
files = JSON.parse(req.query.files);
} catch (e) {}
} catch (e) { }
if (!files || !files.map) {
req.flash("error", "No files selected.");
res.redirect("back");

View File

@ -4,7 +4,8 @@
"version": "0.2.4",
"scripts": {
"format": "prettier --write .",
"start": "node index.js"
"start": "node index.js",
"dev": "nodemon index.js"
},
"bin": {
"file-manager": "index.js"
@ -12,7 +13,6 @@
"dependencies": {
"@primer/octicons": "^16.1.1",
"archiver": "^5.3.0",
"body-parser": "^1.19.0",
"bootstrap": "^5.0.0",
"connect-busboy": "^0.0.2",
"connect-flash": "^0.1.1",
@ -31,6 +31,7 @@
"xterm-addon-fit": "^0.5.0"
},
"devDependencies": {
"prettier": "^2.4.1"
"prettier": "^2.4.1",
"nodemon": "^1.18.4"
}
}