mokee commited on
Commit
ad08f49
·
verified ·
1 Parent(s): f6220d1

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +15 -0
server.js CHANGED
@@ -9,6 +9,21 @@ const app = express();
9
  app.use(cors());
10
  app.use(express.json({ limit: '10mb' }));
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  /**
13
  * 核心引擎:将所有图形转为路径并执行布尔运算
14
  */
 
9
  app.use(cors());
10
  app.use(express.json({ limit: '10mb' }));
11
 
12
+ const AUTH_TOKEN = process.env.API_TOKEN;
13
+
14
+ // 🔐 鉴权中间件
15
+ app.use((req, res, next) => {
16
+ const auth = req.headers.authorization;
17
+ if (!auth || !auth.startsWith('Bearer ')) {
18
+ return res.status(401).send('Unauthorized');
19
+ }
20
+ const token = auth.slice(7);
21
+ if (token !== AUTH_TOKEN) {
22
+ return res.status(401).send('Unauthorized');
23
+ }
24
+ next();
25
+ });
26
+
27
  /**
28
  * 核心引擎:将所有图形转为路径并执行布尔运算
29
  */