Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
shop-api-js5
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vadim
shop-api-js5
Commits
61c9d8bb
Commit
61c9d8bb
authored
Dec 07, 2020
by
Vadim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
конец занятия №77
parent
2ddbc097
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
172 additions
and
5 deletions
+172
-5
config.js
app/config.js
+7
-0
db.json
app/db/db.json
+1
-1
products.js
app/products.js
+19
-2
package-lock.json
package-lock.json
+143
-2
package.json
package.json
+1
-0
.gitignore
public/uploads/.gitignore
+1
-0
No files found.
app/config.js
0 → 100644
View file @
61c9d8bb
const
path
=
require
(
'path'
);
const
rootPath
=
__dirname
;
module
.
exports
=
{
rootPath
,
uploadPath
:
path
.
join
(
rootPath
,
'../public/uploads'
)
};
\ No newline at end of file
app/db/db.json
View file @
61c9d8bb
[{
"title"
:
"Новый продукт2"
,
"price"
:
100
,
"description"
:
"Product description"
,
"_id"
:
"po07wU69_bGgD9lJaGBoB"
},{
"title"
:
"Новый продукт3"
,
"price"
:
100
,
"description"
:
"Product description"
,
"_id"
:
"po07wU69_bGgD9lJaGBoA"
},{
"title"
:
"Название продукта3"
,
"price"
:
100
,
"description"
:
"Описание продукта3"
,
"_id"
:
"po07wU69_bGgD9lJaGBoR"
}]
\ No newline at end of file
[{
"title"
:
"Новый продукт2"
,
"price"
:
100
,
"description"
:
"Product description"
,
"_id"
:
"po07wU69_bGgD9lJaGBoB"
},{
"title"
:
"Новый продукт3"
,
"price"
:
100
,
"description"
:
"Product description"
,
"_id"
:
"po07wU69_bGgD9lJaGBoA"
},{
"title"
:
"Название продукта3"
,
"price"
:
100
,
"description"
:
"Описание продукта3"
,
"_id"
:
"po07wU69_bGgD9lJaGBoR"
},{
"title"
:
"TestForm"
,
"price"
:
"123"
,
"description"
:
"Desc!"
,
"_id"
:
"djfxvIUE1PboYuIg3GrqF"
},{
"title"
:
"TEST"
,
"price"
:
"2121"
,
"description"
:
"dcsf"
,
"_id"
:
"XHR1Qm678_6qm5YpC8FwF"
},{
"title"
:
"ProductWithImage"
,
"price"
:
"123"
,
"description"
:
"desc"
,
"_id"
:
"L9oUjrTVNIQAFPgMNkxjS"
},{
"title"
:
"gtest2"
,
"price"
:
"122"
,
"description"
:
"dasd"
,
"_id"
:
"lbZ2pROuopEILrZAP11Wx"
},{
"title"
:
"dasZD"
,
"price"
:
"111"
,
"description"
:
"fsaf"
,
"_id"
:
"vahqDU0OfxrhM5dZ-JWZ0"
,
"image"
:
"32VkzVPFTTYhNCzErV1TC.jpg"
}]
\ No newline at end of file
app/products.js
View file @
61c9d8bb
const
express
=
require
(
'express'
);
const
multer
=
require
(
'multer'
);
const
path
=
require
(
'path'
);
const
router
=
express
.
Router
();
const
db
=
require
(
'./db/fileDb'
);
const
{
nanoid
}
=
require
(
'nanoid'
)
const
{
nanoid
}
=
require
(
'nanoid'
);
const
config
=
require
(
'./config'
)
const
storage
=
multer
.
diskStorage
({
destination
:
(
req
,
file
,
cb
)
=>
{
cb
(
null
,
config
.
uploadPath
);
},
filename
:
(
req
,
file
,
cb
)
=>
{
cb
(
null
,
nanoid
()
+
path
.
extname
(
file
.
originalname
))
}
});
const
upload
=
multer
({
storage
})
db
.
init
();
...
...
@@ -14,12 +27,16 @@ router.get('/:id', (req, res) => {
res
.
send
(
'Single product will be here'
+
req
.
params
.
id
)
});
router
.
post
(
'/'
,
(
req
,
res
)
=>
{
router
.
post
(
'/'
,
upload
.
single
(
'image'
),
(
req
,
res
)
=>
{
console
.
log
(
'Create product'
,
req
.
body
);
const
newProduct
=
{
...
req
.
body
,
_id
:
nanoid
()
};
if
(
req
.
file
)
{
newProduct
.
image
=
req
.
file
.
filename
;
}
db
.
addItem
(
newProduct
);
res
.
send
(
newProduct
)
});
...
...
package-lock.json
View file @
61c9d8bb
...
...
@@ -81,6 +81,11 @@
"picomatch"
:
"^2.0.4"
}
},
"append-field"
:
{
"version"
:
"1.0.0"
,
"resolved"
:
"https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz"
,
"integrity"
:
"sha1-HjRA6RXwsSA9I3SOeO3XubW0PlY="
},
"array-flatten"
:
{
"version"
:
"1.1.1"
,
"resolved"
:
"https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz"
,
...
...
@@ -165,6 +170,20 @@
"fill-range"
:
"^7.0.1"
}
},
"buffer-from"
:
{
"version"
:
"1.1.1"
,
"resolved"
:
"https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz"
,
"integrity"
:
"sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
},
"busboy"
:
{
"version"
:
"0.2.14"
,
"resolved"
:
"https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz"
,
"integrity"
:
"sha1-bCpiLvz0fFe7vh4qnDetNseSVFM="
,
"requires"
:
{
"dicer"
:
"0.2.5"
,
"readable-stream"
:
"1.1.x"
}
},
"bytes"
:
{
"version"
:
"3.1.0"
,
"resolved"
:
"https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz"
,
...
...
@@ -293,6 +312,46 @@
"integrity"
:
"sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
,
"dev"
:
true
},
"concat-stream"
:
{
"version"
:
"1.6.2"
,
"resolved"
:
"https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz"
,
"integrity"
:
"sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw=="
,
"requires"
:
{
"buffer-from"
:
"^1.0.0"
,
"inherits"
:
"^2.0.3"
,
"readable-stream"
:
"^2.2.2"
,
"typedarray"
:
"^0.0.6"
},
"dependencies"
:
{
"isarray"
:
{
"version"
:
"1.0.0"
,
"resolved"
:
"https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
,
"integrity"
:
"sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"readable-stream"
:
{
"version"
:
"2.3.7"
,
"resolved"
:
"https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz"
,
"integrity"
:
"sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw=="
,
"requires"
:
{
"core-util-is"
:
"~1.0.0"
,
"inherits"
:
"~2.0.3"
,
"isarray"
:
"~1.0.0"
,
"process-nextick-args"
:
"~2.0.0"
,
"safe-buffer"
:
"~5.1.1"
,
"string_decoder"
:
"~1.1.1"
,
"util-deprecate"
:
"~1.0.1"
}
},
"string_decoder"
:
{
"version"
:
"1.1.1"
,
"resolved"
:
"https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz"
,
"integrity"
:
"sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg=="
,
"requires"
:
{
"safe-buffer"
:
"~5.1.0"
}
}
}
},
"configstore"
:
{
"version"
:
"5.0.1"
,
"resolved"
:
"https://registry.npmjs.org/configstore/-/configstore-5.0.1.tgz"
,
...
...
@@ -330,6 +389,11 @@
"resolved"
:
"https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz"
,
"integrity"
:
"sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
},
"core-util-is"
:
{
"version"
:
"1.0.2"
,
"resolved"
:
"https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz"
,
"integrity"
:
"sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"cors"
:
{
"version"
:
"2.8.5"
,
"resolved"
:
"https://registry.npmjs.org/cors/-/cors-2.8.5.tgz"
,
...
...
@@ -385,6 +449,15 @@
"resolved"
:
"https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz"
,
"integrity"
:
"sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"dicer"
:
{
"version"
:
"0.2.5"
,
"resolved"
:
"https://registry.npmjs.org/dicer/-/dicer-0.2.5.tgz"
,
"integrity"
:
"sha1-WZbAhrszIYyBLAkL3cCc0S+stw8="
,
"requires"
:
{
"readable-stream"
:
"1.1.x"
,
"streamsearch"
:
"0.1.2"
}
},
"dot-prop"
:
{
"version"
:
"5.3.0"
,
"resolved"
:
"https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz"
,
...
...
@@ -757,6 +830,11 @@
"integrity"
:
"sha512-VjSeb/lHmkoyd8ryPVIKvOCn4D1koMqY+vqyjjUfc3xyKtP4dYOxM44sZrnqQSzSds3xyOrUTLTC9LVCVgLngw=="
,
"dev"
:
true
},
"isarray"
:
{
"version"
:
"0.0.1"
,
"resolved"
:
"https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz"
,
"integrity"
:
"sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"json-buffer"
:
{
"version"
:
"3.0.0"
,
"resolved"
:
"https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz"
,
...
...
@@ -855,8 +933,15 @@
"minimist"
:
{
"version"
:
"1.2.5"
,
"resolved"
:
"https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz"
,
"integrity"
:
"sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
,
"dev"
:
true
"integrity"
:
"sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"mkdirp"
:
{
"version"
:
"0.5.5"
,
"resolved"
:
"https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz"
,
"integrity"
:
"sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ=="
,
"requires"
:
{
"minimist"
:
"^1.2.5"
}
},
"ms"
:
{
"version"
:
"2.1.2"
,
...
...
@@ -864,6 +949,21 @@
"integrity"
:
"sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
,
"dev"
:
true
},
"multer"
:
{
"version"
:
"1.4.2"
,
"resolved"
:
"https://registry.npmjs.org/multer/-/multer-1.4.2.tgz"
,
"integrity"
:
"sha512-xY8pX7V+ybyUpbYMxtjM9KAiD9ixtg5/JkeKUTD6xilfDv0vzzOFcCp4Ljb1UU3tSOM3VTZtKo63OmzOrGi3Cg=="
,
"requires"
:
{
"append-field"
:
"^1.0.0"
,
"busboy"
:
"^0.2.11"
,
"concat-stream"
:
"^1.5.2"
,
"mkdirp"
:
"^0.5.1"
,
"object-assign"
:
"^4.1.1"
,
"on-finished"
:
"^2.3.0"
,
"type-is"
:
"^1.6.4"
,
"xtend"
:
"^4.0.0"
}
},
"nanoid"
:
{
"version"
:
"3.1.18"
,
"resolved"
:
"https://registry.npmjs.org/nanoid/-/nanoid-3.1.18.tgz"
,
...
...
@@ -983,6 +1083,11 @@
"integrity"
:
"sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc="
,
"dev"
:
true
},
"process-nextick-args"
:
{
"version"
:
"2.0.1"
,
"resolved"
:
"https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz"
,
"integrity"
:
"sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
},
"proxy-addr"
:
{
"version"
:
"2.0.6"
,
"resolved"
:
"https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz"
,
...
...
@@ -1050,6 +1155,17 @@
"strip-json-comments"
:
"~2.0.1"
}
},
"readable-stream"
:
{
"version"
:
"1.1.14"
,
"resolved"
:
"https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz"
,
"integrity"
:
"sha1-fPTFTvZI44EwhMY23SB54WbAgdk="
,
"requires"
:
{
"core-util-is"
:
"~1.0.0"
,
"inherits"
:
"~2.0.1"
,
"isarray"
:
"0.0.1"
,
"string_decoder"
:
"~0.10.x"
}
},
"readdirp"
:
{
"version"
:
"3.5.0"
,
"resolved"
:
"https://registry.npmjs.org/readdirp/-/readdirp-3.5.0.tgz"
,
...
...
@@ -1188,6 +1304,11 @@
"resolved"
:
"https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz"
,
"integrity"
:
"sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
},
"streamsearch"
:
{
"version"
:
"0.1.2"
,
"resolved"
:
"https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz"
,
"integrity"
:
"sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
},
"string-width"
:
{
"version"
:
"4.2.0"
,
"resolved"
:
"https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz"
,
...
...
@@ -1228,6 +1349,11 @@
}
}
},
"string_decoder"
:
{
"version"
:
"0.10.31"
,
"resolved"
:
"https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz"
,
"integrity"
:
"sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
},
"strip-ansi"
:
{
"version"
:
"5.2.0"
,
"resolved"
:
"https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz"
,
...
...
@@ -1302,6 +1428,11 @@
"mime-types"
:
"~2.1.24"
}
},
"typedarray"
:
{
"version"
:
"0.0.6"
,
"resolved"
:
"https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz"
,
"integrity"
:
"sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
},
"typedarray-to-buffer"
:
{
"version"
:
"3.1.5"
,
"resolved"
:
"https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz"
,
...
...
@@ -1381,6 +1512,11 @@
"prepend-http"
:
"^2.0.0"
}
},
"util-deprecate"
:
{
"version"
:
"1.0.2"
,
"resolved"
:
"https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz"
,
"integrity"
:
"sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"utils-merge"
:
{
"version"
:
"1.0.1"
,
"resolved"
:
"https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz"
,
...
...
@@ -1423,6 +1559,11 @@
"resolved"
:
"https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz"
,
"integrity"
:
"sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q=="
,
"dev"
:
true
},
"xtend"
:
{
"version"
:
"4.0.2"
,
"resolved"
:
"https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz"
,
"integrity"
:
"sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
}
}
}
package.json
View file @
61c9d8bb
...
...
@@ -12,6 +12,7 @@
"dependencies"
:
{
"
cors
"
:
"^2.8.5"
,
"
express
"
:
"^4.17.1"
,
"
multer
"
:
"^1.4.2"
,
"
nanoid
"
:
"^3.1.18"
},
"devDependencies"
:
{
...
...
public/uploads/.gitignore
0 → 100644
View file @
61c9d8bb
*
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment