Skip to content

Commit

Permalink
refactor: remove express
Browse files Browse the repository at this point in the history
  • Loading branch information
Yizack committed Nov 24, 2024
1 parent c6073d6 commit 93f4c55
Show file tree
Hide file tree
Showing 5 changed files with 430 additions and 788 deletions.
11 changes: 5 additions & 6 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @requires Card
* @requires gistsList
*/
import app from "./../src/appManager.js";
import { hbsRender } from "./../src/appManager.js";
import { getCard } from "./../src/card.js";
import { getGists } from "./../src/gistsList.js";

Expand All @@ -22,11 +22,10 @@ import { getGists } from "./../src/gistsList.js";
* @param {string} req.query.title Title of the card
* @param {Object} res Response object
*/
app.get("/api", async (req, res) => {
export default async (req, res) => {
const card = getCard(req.query, await getGists(req.query.user)); // get card
res.setHeader("Cache-Control", "max-age=0, s-maxage=14400");
res.setHeader("Content-Type", "image/svg+xml"); // set content type to svg
res.render("card", card); // render card template
});

export default app;
const svg = hbsRender("card", card); // render card template
return res.status(200).send(svg);
};
11 changes: 5 additions & 6 deletions api/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @requires Pin
* @requires gist
*/
import app from "./../src/appManager.js";
import { hbsRender } from "./../src/appManager.js";
import { getPin } from "./../src/pin.js";
import { getGist } from "./../src/gist.js";

Expand All @@ -22,11 +22,10 @@ import { getGist } from "./../src/gist.js";
* @param {boolean} req.query.owner Show gist owner
* @param {Object} res Response object
*/
app.get("/api/pin", async (req, res) => {
export default async (req, res) => {
const pin = await getPin(req.query, await getGist(req.query.id)); // get card
res.setHeader("Cache-Control", "max-age=0, s-maxage=14400");
res.setHeader("Content-Type", "image/svg+xml"); // set content type to svg
res.render("pin", pin); // render pin template
});

export default app;
const svg = hbsRender("pin", pin); // render pin template
return res.status(200).send(svg);
};
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@
"lint": "eslint --fix"
},
"devDependencies": {
"@eslint/compat": "^1.2.1",
"@stylistic/eslint-plugin": "^2.9.0",
"@vitest/coverage-v8": "^2.1.3",
"@eslint/compat": "^1.2.3",
"@stylistic/eslint-plugin": "^2.11.0",
"@vitest/coverage-v8": "^2.1.5",
"clean-jsdoc-theme": "^4.3.0",
"dotenv": "^16.4.5",
"eslint": "^9.13.0",
"express": "^4.21.1",
"eslint": "^9.15.0",
"hbs": "^4.2.0",
"jsdoc": "^4.0.4",
"ofetch": "^1.4.1",
"supertest": "^7.0.0",
"vercel": "^37.12.1",
"vitest": "^2.1.3"
"vercel": "^39.1.1",
"vitest": "^2.1.5"
},
"packageManager": "pnpm@9.12.2"
"packageManager": "pnpm@9.14.2"
}
Loading

0 comments on commit 93f4c55

Please sign in to comment.