From a812acb4d0050e56c1d4ce74f63290246e471dac Mon Sep 17 00:00:00 2001 From: febryardiansyah Date: Sun, 26 Jul 2020 19:25:07 +0700 Subject: [PATCH] fix 404 --- .gitignore | 3 ++- README.md | 32 ++++++++++++++++++++++++++++---- index.js | 2 +- public/index.html | 14 ++++++++++---- public/index.js | 6 ------ public/style.css | 31 +++++++++++++++++++++++++++++++ routers/handleError.js | 8 +++++++- routers/manga.js | 13 +++++++++---- 8 files changed, 88 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 096746c..fe716e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/node_modules/ \ No newline at end of file +/node_modules/ +.vercel \ No newline at end of file diff --git a/README.md b/README.md index fc271f0..06c37d7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -## Manga API +# Manga API Restful API Manga bahasa Indonesia built with ❤️ and node.js -## Usage +# Usage 1. Clone this repository ```bash git clone https://github.com/febryardiansyah/manga-api.git @@ -13,5 +13,29 @@ Restful API Manga bahasa Indonesia built with ❤️ and node.js ``` 4. visit http://localhost:3000/api -## Routes -lazy af rn, i'll add later lmao 😬 \ No newline at end of file +# Documentation +__API__ __PATH__ = http://localhost:3000/api +__ApI__ Version = `v1.0` + +## Get All Manga +Get Latest Manga Update + +```bash +/manga/page/[pageNumber] +``` + +Returns +``` +bash +{ +manga_list: [ + { + title: "My Wife is a Demon Queen ", + thumb: "https://i0.wp.com/komiku.co.id/wp-content/uploads/Manhua-My-Wife-is-a-Demon-Queen.jpg?resize=450,235&quality=60", + type: "Manhua", + updated_on: "2 jam lalu Berwarna", + endpoint: "my-wife-is-a-demon-queen/", + chapter: "Chapter 212" + }, +] +``` diff --git a/index.js b/index.js index b55bd97..8182b4e 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ const chapter = require('./routers/chapter') const cors = require('cors') app.use(cors()) -app.use('/api',manga,require('./routers/handleError')) +app.use('/api',require('./routers/handleError').router,manga) app.use(express.static('./public')) app.use('/api/chapter',chapter) app.listen(PORT, function () { diff --git a/public/index.html b/public/index.html index 195e821..8444803 100644 --- a/public/index.html +++ b/public/index.html @@ -3,13 +3,19 @@ + Home - - - -
+

Selamat Datang di MangaMint Api

+

Jangan lupa bernafas ya xiixixiix 😭

+ \ No newline at end of file diff --git a/public/index.js b/public/index.js index 871f7ca..e69de29 100644 --- a/public/index.js +++ b/public/index.js @@ -1,6 +0,0 @@ -'use strict'; -const e = React.createElement; -const App = require('./app') - -const domContainer = document.querySelector('#root'); -ReactDOM.render(e(App), domContainer); \ No newline at end of file diff --git a/public/style.css b/public/style.css index e69de29..71c5d92 100644 --- a/public/style.css +++ b/public/style.css @@ -0,0 +1,31 @@ +html { + display: table; + margin: auto; +} +body{ + height: 100%; + background-color: #E8505B; + margin: 0; + color: white; +} +nav ul{ + margin:0; + padding:0; + display:flex; + justify-content:space-between; + text-align: center; +} +nav li{ + list-style: none; + padding:1em 0; +} +nav li a{ + color: white; + font-weight: bold; + opacity: 0.5; + text-decoration:none ; + transition:0.3s; +} +nav li a:hover{ + opacity: 1; +} \ No newline at end of file diff --git a/routers/handleError.js b/routers/handleError.js index 1c55f7d..15fa5b1 100644 --- a/routers/handleError.js +++ b/routers/handleError.js @@ -4,4 +4,10 @@ router.get('/', function (req, res){ res.send('Welcome to Manga-API') }) -module.exports = router \ No newline at end of file +const on404 =(req,res) => { + res.status(404).json({ + manga_list:[] + }) +} + +module.exports = {router,on404} \ No newline at end of file diff --git a/routers/manga.js b/routers/manga.js index e81a1a7..bbcd7f3 100644 --- a/routers/manga.js +++ b/routers/manga.js @@ -2,6 +2,7 @@ const router = require('express').Router() const cheerio = require('cheerio') const baseUrl = require('../constants/urls') const { default: Axios } = require('axios') +const on404 = require('./handleError').on404 const replaceMangaPage = 'https://komiku.co.id/manga/' //manga popular ----Ignore this for now -------- @@ -73,7 +74,8 @@ router.get('/manga/page/:pagenumber',(req,res,next)=>{ res.status(200).json({manga_list}) }).catch(error => { - res.send(error) + on404(req,res) + console.log(err.message) }) }) @@ -137,7 +139,8 @@ router.get('/genres/:slug/:pagenumber',(req,res,next)=>{ }) res.json({manga_list}) }).catch(err =>{ - res.send(err) + on404(req,res) + console.log(err.message) }) }) @@ -160,7 +163,8 @@ router.get('/manga/popular/:pagenumber',function(req,res,next) { }) res.json({manga_list}) }).catch(err=>{ - res.send(err) + on404(req,res) + console.log(err.message) }) }) @@ -213,7 +217,8 @@ function getManhuaManhwa(req,res,type) { res.status(200).json({manga_list}) }).catch(err =>{ - res.send(err) + on404(req,res) + console.log(err.message) }) }