diff --git a/index.js b/index.js index 584cbe3..5523682 100644 --- a/index.js +++ b/index.js @@ -5,4 +5,8 @@ test hotfix refactor -*/ \ No newline at end of file +1) GET - READ DATA +2) POST - CREATE DATA +3) PUT - UPDATE DATA +4) DELETE - DELETE DATA +*/ diff --git a/package.json b/package.json index 13f6064..900f871 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node ./server.js" }, "repository": { "type": "git", diff --git a/server.js b/server.js index fe09224..c5314fa 100644 --- a/server.js +++ b/server.js @@ -2,18 +2,41 @@ const express = require('express'); const app = express(); +const cars = [ + 'Audi', + 'Volga', + 'BMW', +]; +// filter +// eslint-disable-next-line func-names +// const filter = function () { +// const tmp = {}; +// // eslint-disable-next-line no-return-assign +// return cars.filter(a => (a in tmp ? 0 : tmp[a] = 1)); +// }; +// filter + app.get('/', (req, res) => { - res.send('
Hello world
'); + res.send(cars.join('
')); }); -// больше не хуйни -app.get('/hello/:name', (req, res) => { +app.get('/cars/add/:name', (req, res) => { const { name, } = req.params; - res.send(`
Hello ${name}
`); + + function filters(cars, name) { + for (let i = 0; i < cars.length; ++i) { + if (cars[i] === name) { + return res.send('Already have'); + } + } + res.send(`ok ${name} add`); + return cars.push(name); + } + filters(cars, name); }); app.listen(3005 || undefined, () => { - console.log('Server started'); + console.log('Server started!!!'); });