diff options
-rw-r--r-- | index.js | 20 | ||||
-rw-r--r-- | routes/web.js | 23 |
2 files changed, 25 insertions, 18 deletions
@@ -1,5 +1,6 @@ const express = require('express'); const exphbs = require('express-handlebars'); +const webRoutes = require('./routes/web'); const app = express(); @@ -10,23 +11,6 @@ app.use(express.static('public')); app.use(express.urlencoded({extended: false})); -app.get('/', (req, res) => { - res.render('home', { - title: 'Home Page', - home: true - }); -}); - -app.get('/new-post', (req, res) => { - res.render('new-post', { - title: 'Make A New Post', - newPost: true - }); -}); - -app.post('/new-post', (req, res) => { - console.log(req.body); - res.redirect('/'); -}); +app.use('/', webRoutes); app.listen(8080, () => console.log('Server started on port 8080.')); diff --git a/routes/web.js b/routes/web.js new file mode 100644 index 0000000..a1a7b01 --- /dev/null +++ b/routes/web.js @@ -0,0 +1,23 @@ +const express = require('express'); +const router = express.Router(); + +router.get('/', (req, res) => { + res.render('home', { + title: 'Home Page', + home: true + }); +}); + +router.get('/new-post', (req, res) => { + res.render('new-post', { + title: 'Make A New Post', + newPost: true + }); +}); + +router.post('/new-post', (req, res) => { + console.log(req.body); + res.redirect('/'); +}); + +module.exports = router; |