feat: add auth mode and refactor frontend (#21)

This commit is contained in:
Dream Hunter
2023-09-09 16:00:10 +08:00
committed by GitHub
parent 9d18f7b59b
commit a395b951e8
10 changed files with 311 additions and 239 deletions

View File

@@ -22,6 +22,9 @@ api.get('/open_api/settings', async (c) => {
return c.json({
"prefix": c.env.PREFIX,
"domains": c.env.DOMAINS,
"auth": (
c.env.PASSWORDS && c.env.PASSWORDS.length > 0
) ? true : false,
});
})

View File

@@ -8,6 +8,13 @@ import { email } from './email';
const app = new Hono()
app.use('/*', cors());
app.use('/api/*', async (c, next) => {
// check header x-custom-auth
if (c.env.PASSWORDS && c.env.PASSWORDS.length > 0) {
const auth = c.req.headers.get("x-custom-auth");
if (!auth || !c.env.PASSWORDS.includes(auth)) {
return c.text("Need Password", 401)
}
}
if (c.req.path.startsWith("/api/new_address")) {
await next();
return;

View File

@@ -5,6 +5,8 @@ node_compat = true
[vars]
PREFIX = "tmp"
# IF YOU WANT TO MAKE YOUR SITE PRIVATE, UNCOMMENT THE FOLLOWING LINES
# PASSWORDS = ["123", "456"]
DOMAINS = ["xxx.xxx1" , "xxx.xxx2"]
JWT_SECRET = "xxx"
BLACK_LIST = ""