Upload files to "/"
This commit is contained in:
parent
daa46029e6
commit
6d81495a38
44
index.js
Normal file
44
index.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
const express = require('express');
|
||||
const app = express();
|
||||
const bodyParser = require('body-parser');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const usersController = require('./controllers/users');
|
||||
const matchController = require('./controllers/matchcontroller');
|
||||
const social = require('./controllers/social')
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
function authenticateJWT(req, res, next) {
|
||||
const token = req.headers['authorization'] && req.headers['authorization'].split(' ')[1];
|
||||
|
||||
if (!token) return res.status(403).json({ error: 'Access denied. No token provided.' });
|
||||
|
||||
jwt.verify(token, process.env.JWT_SECRET, (err, user) => {
|
||||
if (err) return res.status(403).json({ error: 'Invalid token.' });
|
||||
req.user = user;
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
// user management endpoints
|
||||
app.post('/register', usersController.registerUser);
|
||||
app.post('/login', usersController.authenticateUser);
|
||||
app.post('/leaderboards', usersController.getLeaderboard);
|
||||
app.post('/reset-password', authenticateJWT, usersController.resetPassword);
|
||||
|
||||
// social interaction endpoints
|
||||
app.post('/add_friend', authenticateJWT, social.addFriend);
|
||||
|
||||
// match controller
|
||||
app.post('/create-match', authenticateJWT, matchController.createMatch);
|
||||
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
res.send('Server is running!');
|
||||
});
|
||||
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
});
|
1462
package-lock.json
generated
Normal file
1462
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
17
package.json
Normal file
17
package.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "dthpp-node",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bcrypt": "^5.1.1",
|
||||
"express": "^4.21.2",
|
||||
"pg": "^8.13.3"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue