aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.js20
-rw-r--r--routes/web.js23
2 files changed, 25 insertions, 18 deletions
diff --git a/index.js b/index.js
index 81e84a3..1905e3c 100644
--- a/index.js
+++ b/index.js
@@ -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;