├── .env ├── .DS_Store ├── README.md ├── package.json ├── index.js └── data.json /.env: -------------------------------------------------------------------------------- 1 | PORT=9000 2 | CLIENT_URL=http://localhost:3000 -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abbasikov/vertrical_test_backend/HEAD/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Backend App 2 | 3 | ## Installation 4 | 5 | Backend app installation 6 | ```bash 7 | npm install 8 | ``` 9 | 10 | ## Run 11 | 12 | ```bash 13 | npm run dev 14 | ``` -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backend-app", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "dev": "nodemon index", 9 | "start": "node index" 10 | }, 11 | "keywords": [], 12 | "author": "", 13 | "license": "ISC", 14 | "dependencies": { 15 | "compression": "^1.7.4", 16 | "cors": "^2.8.5", 17 | "dotenv": "^16.0.0", 18 | "express": "^4.17.3" 19 | }, 20 | "devDependencies": { 21 | "nodemon": "^2.0.15" 22 | } 23 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const data = require('./data.json') 3 | const compression = require('compression') 4 | require('dotenv').config() 5 | var cors = require('cors') 6 | const app = express() 7 | 8 | app.use(compression()) 9 | app.use(cors({ 10 | origin: process.env.CLIENT_URL, 11 | optionsSuccessStatus: 200 12 | })) 13 | const port = process.env.PORT || 9000 14 | 15 | app.get('/', (req, res) => { 16 | const searchTerm = req.query.title.toLowerCase() 17 | const result = data.filter(item => item.title.includes(searchTerm)) 18 | if (!result.length) 19 | res.status(404).send("Title not found!!!") 20 | else res.json(result) 21 | }) 22 | 23 | app.listen(port, () => { 24 | console.log(`Example app listening on port ${port}`) 25 | }) -------------------------------------------------------------------------------- /data.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 1, 4 | "title": "flower", 5 | "photo": "https://wallpaperaccess.com/full/109672.jpg", 6 | "description": "dfja;skdfj;alkg", 7 | "subDescription": "Cars have controls for driving, parking," 8 | }, 9 | { 10 | "id": 2, 11 | "title": "bike", 12 | "photo": "https://wallpaperaccess.com/full/109672.jpg", 13 | "description": "ajdflkasjf;alfjfja;ldf", 14 | "subDescription": "Cars have controls for driving, parking," 15 | }, 16 | { 17 | "id": 3, 18 | "title": "car", 19 | "photo": "https://wallpaperaccess.com/full/109672.jpg", 20 | "description": "dfja;skdfj;alkg", 21 | "subDescription": "Cars have controls for driving, parking," 22 | }, 23 | { 24 | "id": 4, 25 | "title": "train", 26 | "photo": "https://cdn.wallpapersafari.com/37/84/jF1ZcU.jpg", 27 | "description": "ajdflkasjf;alfjfja;ldf", 28 | "subDescription": "Cars have controls for driving, parking," 29 | }, 30 | { 31 | "id": 5, 32 | "title": "train", 33 | "photo": "https://cdn.wallpapersafari.com/37/84/jF1ZcU.jpg", 34 | "description": "ajdflkasjf;alfjfja;ldf", 35 | "subDescription": "Cars have controls for driving, parking," 36 | }, 37 | { 38 | "id": 6, 39 | "title": "train", 40 | "photo": "https://cdn.wallpapersafari.com/37/84/jF1ZcU.jpg", 41 | "description": "ajdflkasjf;alfjfja;ldf", 42 | "subDescription": "Cars have controls for driving, parking," 43 | } 44 | ] --------------------------------------------------------------------------------