Skip to content

Commit 083f18f

Browse files
committed
password protection
1 parent f9b2177 commit 083f18f

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const config = {
2+
passwordProtect: false,
3+
password: "password"
4+
}

index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import express from 'express'
2+
import basicAuth from "express-basic-auth";
23
import http from 'node:http'
34
import { createBareServer } from '@tomphttp/bare-server-node'
45
import path from 'node:path'
56
import cors from 'cors'
6-
7+
import { config } from './config.js'
78
const __dirname = process.cwd()
89
const server = http.createServer()
910
const app = express(server)
1011
const bareServer = createBareServer('/v/')
1112
const PORT = 8080
12-
13+
if (config.passwordProtect === true) {
14+
console.log("Password protection is enabled. Username is 'interstellar'.")
15+
console.log("Password is: " + config.password)
16+
app.use(basicAuth({
17+
users: { "interstellar" : config.password },
18+
challenge: true
19+
}))
20+
} else {
21+
console.log("Password protection is disabled.")
22+
}
1323
app.use(express.json())
1424
app.use(express.urlencoded({ extended: true }))
1525
app.use(cors())

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
},
99
"scripts": {
1010
"start": "node index.js",
11-
"format": "npx prettier . --write"
11+
"format": "npx prettier . --write",
12+
"password-start": "node password.js"
1213
},
1314
"author": "",
1415
"license": "GPL-3.0-or-later",
1516
"dependencies": {
16-
"@titaniumnetwork-dev/ultraviolet": "^1.0.10",
1717
"@tomphttp/bare-server-node": "^2.0.1",
1818
"cors": "^2.8.5",
19-
"express": "^4.18.2"
19+
"express": "^4.18.2",
20+
"express-basic-auth": "^1.2.1"
2021
},
2122
"devDependencies": {
2223
"prettier": "3.2.1"

0 commit comments

Comments
 (0)