Permalink
Browse files

Added express app

  • Loading branch information...
marcomontalbano committed Oct 2, 2018
1 parent bcd1ab9 commit ae7a4ec21148ec0cb58da7ab9fac1ae046e8e88b
Showing with 573 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +36 −0 db.example.json
  3. +17 −0 example-express.js
  4. +28 −0 example-node.js
  5. +415 −0 package-lock.json
  6. +20 −0 package.json
  7. +54 −0 server.js
View
@@ -59,3 +59,6 @@ typings/
# next.js build output
.next
#
db.json
View
@@ -0,0 +1,36 @@
{
"articles": [
{
"id": 1,
"title": "Article Title 1",
"picture": "https://placeimg.com/640/480/tech?1",
"plot": "Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.",
"tag": "tech",
"like": false
},
{
"id": 2,
"title": "Article Title 2",
"picture": "https://placeimg.com/640/480/tech?2",
"plot": "Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.",
"tag": "tech",
"like": true
},
{
"id": 3,
"title": "Article Title 3",
"picture": "https://placeimg.com/640/480/tech?3",
"plot": "Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.",
"tag": "tech",
"like": false
},
{
"id": 4,
"title": "Article Title 4",
"picture": "https://placeimg.com/640/480/tech?4",
"plot": "Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.",
"tag": "tech",
"like": false
}
]
}
View
@@ -0,0 +1,17 @@
var express = require('express');
var app = express();
app.get('/articles', function (req, res) {
res.send([{
"id": 1,
"title": "Article Title 1",
"picture": "https://placeimg.com/640/480/tech?1",
"plot": "Lorem ipsum.",
"tag": "tech",
"like": false
}]);
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
View
@@ -0,0 +1,28 @@
var http = require('http');
var hostname = '127.0.0.1', port = 3000;
var server = http.createServer(function (req, res) {
var response = [{}];
if (req.method === 'GET' && req.url === '/articles') {
response = [{
"id": 1,
"title": "Article Title 1",
"picture": "https://placeimg.com/640/480/tech?1",
"plot": "Lorem ipsum.",
"tag": "tech",
"like": false
}];
}
res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.end( JSON.stringify(response) );
});
server.listen(port, hostname, function () {
console.log('Server running at http://' + hostname + ':' + port + '/');
});
Oops, something went wrong.

0 comments on commit ae7a4ec

Please sign in to comment.