Skip to content

Instantly share code, notes, and snippets.

@edgvi10
Last active February 27, 2022 01:09
Show Gist options
  • Select an option

  • Save edgvi10/413eb2fa76c02d42f65f4ac78e62e8e0 to your computer and use it in GitHub Desktop.

Select an option

Save edgvi10/413eb2fa76c02d42f65f4ac78e62e8e0 to your computer and use it in GitHub Desktop.

Revisions

  1. edgvi10 revised this gist Feb 27, 2022. 1 changed file with 23 additions and 12 deletions.
    35 changes: 23 additions & 12 deletions javascript.json
    Original file line number Diff line number Diff line change
    @@ -5,18 +5,29 @@
    "handler"
    ],
    "body": [
    "export default async function handler(req, res) {",
    " if (req.method === \"PUT\") {",
    " res.status(200).json({});",
    " } else if (req.method === \"GET\") {",
    " res.status(200).json({});",
    " } else if (req.method === \"POST\") {",
    " res.status(200).json({});",
    " } else if (req.method === \"DELETE\") {",
    " res.status(204).json({});",
    " } else {",
    " res.status(405).json({error: true});",
    " }",
    "export default async function (req, res) {",
    " console.clear();",
    " console.log(`${req.method} ${req.url}`);",
    "",
    " const $return = {};",
    " $return.success = false;",
    " $return.message = \"\";",
    "",
    " if (req.method === \"POST\") {",
    "",
    " return res.status($return.statusCode || 201).json({ ...$return });",
    " } else if (req.method === \"GET\") {",
    "",
    " return res.status($return.statusCode || 200).json({ ...$return });",
    " } else if (req.method === \"PUT\") {",
    "",
    " return res.status($return.statusCode || 200).json({ ...$return });",
    " } else if (req.method === \"DELETE\") {",
    "",
    " return res.status($return.statusCode || 200).json({ ...$return });",
    " }",
    "",
    " return res.status(405).json({ ...$return, error: \"Method Not Allowed\" });",
    "}"
    ],
    "description": "initial handler to nextjs routes."
  2. edgvi10 created this gist Feb 12, 2022.
    24 changes: 24 additions & 0 deletions javascript.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    {
    "Next Routes handler": {
    "prefix": [
    "nexthandler",
    "handler"
    ],
    "body": [
    "export default async function handler(req, res) {",
    " if (req.method === \"PUT\") {",
    " res.status(200).json({});",
    " } else if (req.method === \"GET\") {",
    " res.status(200).json({});",
    " } else if (req.method === \"POST\") {",
    " res.status(200).json({});",
    " } else if (req.method === \"DELETE\") {",
    " res.status(204).json({});",
    " } else {",
    " res.status(405).json({error: true});",
    " }",
    "}"
    ],
    "description": "initial handler to nextjs routes."
    }
    }
    20 changes: 20 additions & 0 deletions json.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    {
    "Next Package": {
    "prefix": [
    "package",
    "package"
    ],
    "body": [
    "{",
    " \"name\": \"${1}\",",
    " \"version\": \"0.0.1\",",
    " \"scripts\": {",
    " \"build\": \"next build\",",
    " \"start\": \"next start\",",
    " \"dev\": \"next dev\"",
    " }",
    "}"
    ],
    "description": "initial handler to nextjs routes."
    }
    }