Remove dev folder
This commit is contained in:
parent
afb67f34d4
commit
85458c05e4
@ -1,40 +0,0 @@
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
const jwt = require('jsonwebtoken'); // Import the jsonwebtoken library
|
||||
|
||||
const app = express();
|
||||
const PORT = 5000;
|
||||
const cors = require('cors');
|
||||
|
||||
const corsOptions = {
|
||||
origin: 'http://127.0.0.1:5500', // Replace with your frontend's origin
|
||||
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
||||
credentials: true,
|
||||
optionsSuccessStatus: 204,
|
||||
};
|
||||
|
||||
app.use(cors(corsOptions));
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
const secretKey = 'your-secret-key';
|
||||
|
||||
app.post('/api/auth', (req, res) => {
|
||||
const { user_name, password } = req.body;
|
||||
// Check the username and password (for demonstration purposes, accept any non-empty values)
|
||||
if (user_name==="Yash" && password==="123") {
|
||||
// Authentication successful, create a JWT token
|
||||
const token = jwt.sign({ user_name }, secretKey, { expiresIn: '1h' }); // Token expires in 1 hour
|
||||
res.json({ token });
|
||||
} else {
|
||||
// Authentication failed
|
||||
res.status(401).json({ error: 'Invalid username or password' });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
});
|
||||
>>>>>>> b1b896f (Add api request changes)
|
Loading…
x
Reference in New Issue
Block a user