-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8de8f93
commit 01104c7
Showing
6 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
node_modules | ||
.env | ||
build | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,38 @@ | ||
const config = require('./utils/config') | ||
const express = require('express') | ||
const app = express() | ||
const cors = require('cors') | ||
const mongoose = require('mongoose') | ||
|
||
const app = express() | ||
const blogSchema = new mongoose.Schema({ | ||
title: String, | ||
author: String, | ||
url: String, | ||
likes: Number, | ||
}) | ||
|
||
const Blog = mongoose.model('Blog', blogSchema) | ||
|
||
mongoose.connect(config.MONGODB_URI) | ||
|
||
app.use(cors()) | ||
app.use(express.json()) | ||
|
||
app.get('/api/blogs', (request, response) => { | ||
Blog.find({}).then((blogs) => { | ||
response.json(blogs) | ||
}) | ||
}) | ||
|
||
app.post('/api/blogs', (request, response) => { | ||
const blog = new Blog(request.body) | ||
|
||
app.get('/', (request, response) => { | ||
response.send('<h1>Hello World!</h1>') | ||
blog.save().then((result) => { | ||
response.status(201).json(result) | ||
}) | ||
}) | ||
|
||
const PORT = process.env.PORT || 3001 | ||
const PORT = config.PORT | ||
app.listen(PORT, () => { | ||
console.log(`Server running on port ${PORT}`) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
POST http://localhost:3003/api/blogs | ||
Content-Type: application/json | ||
|
||
{ | ||
"title": "Test of blog title", | ||
"author": "Test of blog author", | ||
"url": "Test of blog url", | ||
"likes": 0 | ||
} | ||
|
||
### | ||
GET http://localhost:3003/api/blogs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require('dotenv').config() | ||
|
||
const PORT = process.env.PORT | ||
const MONGODB_URI = process.env.MONGODB_URI | ||
|
||
module.exports = { | ||
MONGODB_URI, | ||
PORT, | ||
} |