mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-05-11 18:10:01 +08:00
feat: add auth mode and refactor frontend (#21)
This commit is contained in:
@@ -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,
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = ""
|
||||
|
||||
Reference in New Issue
Block a user