simoncck commited on
Commit
2db46c6
·
verified ·
1 Parent(s): 048202f

Create server.js

Browse files
Files changed (1) hide show
  1. server.js +26 -0
server.js ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import express from 'express';
2
+ import { runLogin } from './login.js';
3
+
4
+ const PORT = process.env.PORT || 3000;
5
+ /*const TOKEN = process.env.API_KEY || '';*/ // optional simple auth
6
+
7
+ const app = express();
8
+ app.use(express.json());
9
+
10
+ /* POST /login { "key": "secret" } */
11
+ app.post('/login', async (req, res) => {
12
+ /* if (TOKEN && req.body.key !== TOKEN)
13
+ return res.status(401).json({ error: 'unauthorized' });*/
14
+
15
+ // optional: debounce so two calls don't overlap
16
+ if (app.locals.running) return res.status(429).json({ error: 'busy' });
17
+ app.locals.running = true;
18
+
19
+ const result = await runLogin();
20
+ app.locals.running = false;
21
+
22
+ res.json(result);
23
+ });
24
+
25
+ app.listen(PORT, () =>
26
+ console.log(`🔐 n8n-login API listening on ${PORT}`));