From b122279ece06a9381e805c6087f130b41616fe3d Mon Sep 17 00:00:00 2001 From: Geo Halkiadakis Date: Fri, 12 Apr 2024 18:31:00 +0300 Subject: added utils folder; added several suplamentary modules --- paths.js | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'paths.js') diff --git a/paths.js b/paths.js index a2af434..6e5fbef 100644 --- a/paths.js +++ b/paths.js @@ -1,16 +1,24 @@ +/** + * defines routes + * exports router + */ + const Router = require('koa-router'); +const urler = require('./utils/url-util'); -const kb = require('./pieces/kb-util.js'); const data = require('./pieces/prepare-streams'); -const products = require('./data/products.json'); + const bench = require('./benchmark/find.js'); -const macthStr = require('./benchmark/match-str.js'); +const matchStr = require('./benchmark/match-str.js'); + // Prefix all routes with: /items const router = new Router({ // prefix: '/items' }); + + /* simple route example let items = [ @@ -50,7 +58,6 @@ const router = new Router({ // Routes - router.get('/', (ctx, next) => { ctx.body = { success: true, @@ -68,6 +75,7 @@ router.get('/search', (ctx, next) => { router.get('/search/:title', (ctx, next) => { // console.log(ctx); + const kb = require('./utils/kb-util.js'); let words = kb.keyboardize(kb.clean(ctx.params.title)).split(' '); ctx.body = { params: ctx.params, @@ -93,8 +101,7 @@ router.get('/search/:title', (ctx, next) => { router.get('/test', (ctx, next) => { // easy test route // test anything ... - let result = { success: true, data: [1, 2, 3] }; - ctx.body = result; + ctx.body = { params: urler.struct(ctx.request, ctx.url), ctx: ctx } next(); }); @@ -111,24 +118,30 @@ router.get('/test/do-data', (ctx, next) => { // easy test route next(); }); -router.get('/test/json', (ctx, next) => { // easy test route - // test anything ... - ctx.body = { t: + new Date(), p: products }; - next(); -}); +// benchmark routes; +// shall be removed from production +//////////////////////////////////////////////////////////////////////////////// + +/// router.get('/test/json', (ctx, next) => { // easy test route +/// // test anything ... +/// ctx.body = { t: + new Date(), p: products }; +/// next(); +/// }); -router.get('/bench/fe', (ctx, next) => { // easy test route +router.get('/bench/find', (ctx, next) => { // easy test route // test anything ... - // ctx.body = bench.compare(); ctx.body = bench.compare(); next(); }); -router.get('/bench/match', (ctx, next) => { // easy test route - // test anything ... +router.get('/bench/match/:title', (ctx, next) => { // easy test route + // test anything ... [ query = 'solokata' ] // ctx.body = bench.compare(); - ctx.body = macthStr.run(); + ctx.body = matchStr.run(ctx.params.title); next(); }); -module.exports = router; \ No newline at end of file + +// export routes + +module.exports = router; -- cgit v1.2.3