diff options
Diffstat (limited to 'part4/blog/src/index.js')
-rw-r--r-- | part4/blog/src/index.js | 40 |
1 files changed, 9 insertions, 31 deletions
diff --git a/part4/blog/src/index.js b/part4/blog/src/index.js index ff25ad4..7c56c4e 100644 --- a/part4/blog/src/index.js +++ b/part4/blog/src/index.js @@ -1,47 +1,25 @@ const express = require('express') const app = express() const cors = require('cors') +const Blog = require('../models/blog.js') +const blogsRouter = require('../controllers/blogs') const mongoose = require('mongoose') +const logger = require('../utils/logger.js') -const blogSchema = new mongoose.Schema({ - title: String, - author: String, - url: String, - likes: Number -}) - -const Blog = mongoose.model('Blog', blogSchema) -console.log("Connecting to mongo server") -const mongoUrl = 'somewhereLOL' +logger.info("Connecting to mongo server") +const mongoUrl = 'hello' mongoose.connect(mongoUrl) -console.log("Successfully connected to mongo server") +logger.info("Successfully connected to mongo server") app.use(cors()) app.use(express.json()) -app.get('/api/blogs', (request, response) => { - Blog - .find({}) - .then(blogs => { - response.json(blogs) - }) - .catch((error) => { - console.log(error.message) - }) -}) +app.get('/api/blogs', blogsRouter) -app.post('/api/blogs', (request, response) => { - const blog = new Blog(request.body) - - blog - .save() - .then(result => { - response.status(201).json(result) - }) -}) +app.post('/api/blogs', blogsRouter) const PORT = 3003 app.listen(PORT, () => { - console.log(`Server running on port ${PORT}`) + logger.info(`Server running on port ${PORT}`) }) |