Readlebee/server/routes/search.js

13 lines
579 B
JavaScript
Raw Normal View History

2019-09-07 01:20:27 +02:00
const SearchController = require('../controllers/search');
async function routes(fastify, options) {
fastify.get('/search', async (request, reply) => {
const searchTerm = typeof request.query.for !== 'undefined' ? request.query.for.trim() : '';
const search = new SearchController(searchTerm);
const results = await search.searchOpenLibrary();
2019-09-07 06:17:45 +02:00
reply.view('search.hbs', { results, searchTerm, arbitraryContent: request.isLoggedInUser ? JSON.stringify(fastify.jwt.decode(request.cookies.token)) : 'you are NOT logged in' });
2019-09-07 01:20:27 +02:00
});
}
module.exports = routes