updated exports

This commit is contained in:
Joseph D Thompson 2025-03-19 15:02:42 -05:00
parent f56eccefbd
commit c1c77efaf0

View File

@ -1,26 +1,12 @@
// server/index.js // license-lib/server/index.js
const express = require('express');
const { generateLicenseKey, hashLicenseKey } = require('./keygen'); const { generateLicenseKey, hashLicenseKey } = require('./keygen');
const { saveLicense } = require('./models/license'); const { saveLicense, getLicense } = require('./models/license');
const { verifyLicenseKey } = require('./verify'); const { verifyLicenseKey } = require('./verify');
const app = express(); module.exports = {
app.use(express.json()); generateLicenseKey,
hashLicenseKey,
app.post('/generate-license', async (req, res) => { saveLicense,
const { userId, licenseType, tier, validUntil } = req.body; getLicense,
const licenseKey = generateLicenseKey(userId, licenseType, tier); verifyLicenseKey
const hashedKey = hashLicenseKey(JSON.parse(Buffer.from(licenseKey.split('.')[1], 'base64')).rawKey); };
await saveLicense(userId, hashedKey, licenseType, tier, validUntil);
res.json({ licenseKey });
});
app.post('/validate-license', async (req, res) => {
const { userId, licenseKey } = req.body;
const valid = await verifyLicenseKey(userId, licenseKey);
res.json({ valid });
});
app.listen(3000, () => console.log('License server running on port 3000'));