diff --git a/assets/index.js b/assets/index.js new file mode 100644 index 0000000..5eb3ef0 --- /dev/null +++ b/assets/index.js @@ -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; + diff --git a/index.js b/index.js index 389adff..c0e5076 100755 --- a/index.js +++ b/index.js @@ -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"); diff --git a/package.json b/package.json index c7a280e..93f47b1 100644 --- a/package.json +++ b/package.json @@ -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" } }