Skip to content

Commit

Permalink
Refactor index.js, add routes and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
AntKovachev committed Dec 3, 2024
1 parent dd96f2b commit a3b6a1e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# to-do-app
To do app.


ADD HANDLEBARS
REDIRECT TO CORRECT PAGES
ADD ERROR HANDLING
ADD SOME USER SESSION
ADD OWNERID FOR TASKS
REFACTOR INDEX.JS [X]
22 changes: 4 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const express = require('express');
const mongoose = require('mongoose');
const path = require('path');
const taskController = require('./controllers/taskController');
const userController = require('./controllers/userController');

const taskRoutes = require('./routes/task');
const authRoutes = require('./routes/auth');
const app = express();
const PORT = 3000;

Expand All @@ -12,26 +11,13 @@ mongoose.connect('mongodb://localhost:27017/to_do_app');
app.use(express.static(path.join(__dirname)));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(taskRoutes);
app.use(authRoutes);

app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});

app.get('/tasks', taskController.getTasks);
app.post('/submit', taskController.createTask);
app.put('/update/:id', taskController.updateTask);
app.delete('/delete/:id', taskController.deleteTask);

app.get('/register', (req, res) => {
res.sendFile(path.join(__dirname, 'register.html'));
});
app.post('/register', userController.register);

app.get('/login', (req, res) => {
res.sendFile(path.join(__dirname, 'login.html'));
});
app.post('/login', userController.login);

app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
16 changes: 16 additions & 0 deletions routes/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const express = require('express');
const path = require('path');
const userController = require('../controllers/userController');
const router = express.Router();

router.get('/register', (req, res) => {
res.sendFile(path.join(__dirname, '../register.html'));
});
router.post('/register', userController.register);

router.get('/login', (req, res) => {
res.sendFile(path.join(__dirname, '../login.html'));
});
router.post('/login', userController.login);

module.exports = router;
10 changes: 10 additions & 0 deletions routes/task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const express = require('express');
const taskController = require('../controllers/taskController');
const router = express.Router();

router.get('/tasks', taskController.getTasks);
router.post('/submit', taskController.createTask);
router.put('/update/:id', taskController.updateTask);
router.delete('/delete/:id', taskController.deleteTask);

module.exports = router;

0 comments on commit a3b6a1e

Please sign in to comment.