intern-Assignment/PostgreSQL/formPrac/routes/index.js

33 lines
885 B
JavaScript
Raw Permalink Normal View History

2025-01-31 09:50:39 +00:00
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const userAuthentication = require('../middlewares/userAuthentication');
const { signup } = require('../controller/signup');
const { login } = require('../controller/login');
const PORT = 4000;
const app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '..', 'public', 'index.html'));
});
app.post('/login', login);
app.get('/dashboard', userAuthentication, (req, res) => {
res.send('<h1>Welcome to the dashboard</h1> <a href="/logout">Logout</a>');
});
app.get('/logout', (req, res) => {
res.redirect('/login')
});
app.post('/signup', signup);
app.listen(PORT, () => {
console.log(`Server is running on ${PORT}`);
})