randydev commited on
Commit
9d7429f
·
verified ·
1 Parent(s): b193ed1

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +21 -2
index.js CHANGED
@@ -24,9 +24,15 @@ const app = express();
24
  import * as swaggerUi from 'swagger-ui-express';
25
  import * as cheerio from 'cheerio';
26
  import * as lifestyle from './startup/lifestyle.js';
27
-
28
  import { Readable } from "stream";
29
- import { CheckMilWare, authenticateApiKey, apiLimiter} from './middleware/midware.js';
 
 
 
 
 
 
30
  import { setup, serve } from './swagger.js';
31
  import { swaggerOptions } from './settingOptions.js';
32
  import path from "path";
@@ -66,6 +72,19 @@ app.use(
66
 
67
  app.use(express.static('public'));
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  app.get('/protected', authenticateApiKey, apiLimiter, (req, res) => {
71
  res.json({ message: 'Authorized access!' });
 
24
  import * as swaggerUi from 'swagger-ui-express';
25
  import * as cheerio from 'cheerio';
26
  import * as lifestyle from './startup/lifestyle.js';
27
+ import { db } from './database/database.js'
28
  import { Readable } from "stream";
29
+ import {
30
+ CheckMilWare,
31
+ authenticateApiKey,
32
+ apiLimiter,
33
+ myUUID
34
+ } from './middleware/midware.js';
35
+
36
  import { setup, serve } from './swagger.js';
37
  import { swaggerOptions } from './settingOptions.js';
38
  import path from "path";
 
72
 
73
  app.use(express.static('public'));
74
 
75
+ app.post('/generate-key', async (req, res) => {
76
+ try {
77
+ const newKey = myUUID;
78
+ await db('apiKeys').insertOne({
79
+ key: newKey,
80
+ createdAt: new Date(),
81
+ owner: '[email protected]'
82
+ });
83
+ res.json({ apiKey: newKey });
84
+ } catch (err) {
85
+ res.status(500).json({ error: 'Key generation failed' });
86
+ }
87
+ });
88
 
89
  app.get('/protected', authenticateApiKey, apiLimiter, (req, res) => {
90
  res.json({ message: 'Authorized access!' });