mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
First commit
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
|
||||
|
||||
export default function handler(req, res) {
|
||||
res.status(200).json({ name: 'John Doe' })
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import db from "data/icons";
|
||||
|
||||
export default function handler(req, res) {
|
||||
const { id, q } = req.query;
|
||||
|
||||
// we have an id available
|
||||
if (id) {
|
||||
const item = db.find((item) => item.id === +id);
|
||||
return res.status(200).json(item);
|
||||
}
|
||||
|
||||
// we have a keyword to search for
|
||||
if (q) {
|
||||
const results = db.filter((product) => {
|
||||
const { title } = product;
|
||||
return title.toLowerCase().includes(q.toLowerCase());
|
||||
});
|
||||
return res.status(200).json(results);
|
||||
}
|
||||
|
||||
// we don't have anything
|
||||
res.status(400).json();
|
||||
}
|
||||
Reference in New Issue
Block a user