diff options
| author | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2024-04-12 18:31:00 +0300 |
|---|---|---|
| committer | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2024-04-12 18:31:00 +0300 |
| commit | b122279ece06a9381e805c6087f130b41616fe3d (patch) | |
| tree | 2ec0a8fc3c570417d972b18a7a7b878758ce3a6f /paths.js | |
| parent | 762d85c95690f510bec4dd8c37c05454ae1be4fc (diff) | |
| download | oseine-b122279ece06a9381e805c6087f130b41616fe3d.tar.gz oseine-b122279ece06a9381e805c6087f130b41616fe3d.tar.bz2 oseine-b122279ece06a9381e805c6087f130b41616fe3d.zip | |
added utils folder; added several suplamentary modules
Diffstat (limited to 'paths.js')
| -rw-r--r-- | paths.js | 47 |
1 files changed, 30 insertions, 17 deletions
@@ -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; |
