File size: 744 Bytes
2db46c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import express from 'express';
import { runLogin } from './login.js';

const PORT = process.env.PORT || 3000;
/*const TOKEN = process.env.API_KEY || '';*/     // optional simple auth

const app = express();
app.use(express.json());

/* POST /login  { "key": "secret" } */
app.post('/login', async (req, res) => {
/*  if (TOKEN && req.body.key !== TOKEN)
    return res.status(401).json({ error: 'unauthorized' });*/

  // optional: debounce so two calls don't overlap
  if (app.locals.running) return res.status(429).json({ error: 'busy' });
  app.locals.running = true;

  const result = await runLogin();
  app.locals.running = false;

  res.json(result);
});

app.listen(PORT, () =>
  console.log(`🔐 n8n-login API listening on ${PORT}`));