Skip to content

Commit

Permalink
written /getposts route
Browse files Browse the repository at this point in the history
Relates: #10
Co-authored-by: @akomiqaia <[email protected]>
  • Loading branch information
Roger-Heathcote committed Mar 26, 2020
1 parent a061ec9 commit 2336e14
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
10 changes: 10 additions & 0 deletions handlers/getposts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const model = require("../model");

function getPostsHandler(req,res){
console.log("wevs");
let headers = {"content-type": "application/json"}
res.writeHead(200, headers);
res.end(JSON.stringify(model.posts));
}

module.exports = getPostsHandler;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js",
"test": "node ./test.js | tap-spec",
"start": "node server.js",
"start:dev": "nodemon server.js"
},
"repository": {
Expand Down
5 changes: 2 additions & 3 deletions router.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Serves all the static files
const publicHandler = require("./handlers/public");


const getPostsHandler = require("./handlers/getposts");

// Serves homepage.html
// const homeHandler = require("./handlers/home");
Expand All @@ -12,7 +11,7 @@ const publicHandler = require("./handlers/public");
function router(request, response) {
const url = request.url;
if (url === "/getposts") {
// homeHandler(request, response);
getPostsHandler(request, response);
} else if (url.includes("public")) {
publicHandler(request, response);
} else {
Expand Down
16 changes: 14 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
const test = require("tape")
const supertest = require("supertest")
const test = require("tape");
const supertest = require("supertest");
const router = require("./router");

test("Test /getposts returns status 200.", t=> {
supertest(router)
.get("/getposts")
.expect(200)
.expect("content-type", "application/json")
.end( (error, response) => {
t.error(error);
t.equal(response.text, JSON.stringify({}));
t.end();
});
});

0 comments on commit 2336e14

Please sign in to comment.