Skip to content

Commit 3b78970

Browse files
committed
2 parents 2900dfd + d0c31ce commit 3b78970

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

config.js

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

index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
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) {
14+
console.log("Password protection is enabled. Username is 'interstellar'.")
15+
console.log("Password is: " + config.password)
16+
app.use(basicAuth({
17+
users: { "interstellar" : password },
18+
challenge: true
19+
}))
20+
}
1321
app.use(express.json())
1422
app.use(express.urlencoded({ extended: true }))
1523
app.use(cors())

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"dependencies": {
1616
"@tomphttp/bare-server-node": "^2.0.1",
1717
"cors": "^2.8.5",
18-
"express": "^4.18.2"
18+
"express": "^4.18.2",
19+
"express-basic-auth": "^1.2.1"
1920
},
2021
"devDependencies": {
2122
"prettier": "3.2.1"

0 commit comments

Comments
 (0)