Split API from demo app and began Express framework (#7)
parent
0f247eac8c
commit
4d7afab630
|
@ -0,0 +1 @@
|
|||
node_modules/
|
|
@ -0,0 +1,16 @@
|
|||
const express = require("express");
|
||||
const app = express();
|
||||
const apiRoutes = require("routes");
|
||||
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
app.use("/api", apiRoutes);
|
||||
|
||||
app.use("*", (req, res) => {
|
||||
res.status(404).json({ error: "Resource not found" });
|
||||
});
|
||||
|
||||
app.listen(3000, () => {
|
||||
console.log("Suggestion Service API is up!");
|
||||
});
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "oapen-suggestion-service-api",
|
||||
"version": "0.0.1",
|
||||
"description": "An API which allows you to search for books with similar content from the oapen.org library.",
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.18.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const validate = require("./validate");
|
||||
|
||||
router.get("/:handle", async (req, res) => {
|
||||
try {
|
||||
await validate.checkHandle(req.params.handle);
|
||||
//TODO: Call a data function to grab suggestions from DB
|
||||
let responseData = { error: "Not implemented" };
|
||||
res.status(200).json(responseData);
|
||||
} catch (e) {
|
||||
res.status(200).json({});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
|
@ -0,0 +1,8 @@
|
|||
let checkHandle = async (handle) => {
|
||||
// TODO: Validate the book's handle
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
checkHandle,
|
||||
};
|
Loading…
Reference in New Issue