diff --git a/config.js b/config.js new file mode 100644 index 000000000..0cf75b927 --- /dev/null +++ b/config.js @@ -0,0 +1,5 @@ +const config = { + passwordProtect: false, + password: "password" +} +export default config; \ No newline at end of file diff --git a/index.js b/index.js index 2c100c7f7..f838a62e2 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,23 @@ import express from 'express' +import basicAuth from "express-basic-auth"; import http from 'node:http' import { createBareServer } from '@tomphttp/bare-server-node' import path from 'node:path' import cors from 'cors' - +import config from './config.js' const __dirname = process.cwd() const server = http.createServer() const app = express(server) const bareServer = createBareServer('/v/') const PORT = 8080 - +if (config.passwordProtect) { + console.log("Password protection is enabled. Username is 'interstellar'.") + console.log("Password is: " + config.password) + app.use(basicAuth({ + users: { "interstellar" : password }, + challenge: true + })) +} app.use(express.json()) app.use(express.urlencoded({ extended: true })) app.use(cors()) diff --git a/package.json b/package.json index 90a1f4f4c..6965c2b2f 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "dependencies": { "@tomphttp/bare-server-node": "^2.0.1", "cors": "^2.8.5", - "express": "^4.18.2" + "express": "^4.18.2", + "express-basic-auth": "^1.2.1" }, "devDependencies": { "prettier": "3.2.1"