Skip to content

Commit

Permalink
async/await for 404 sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
raclim committed Jul 22, 2024
1 parent d72fa53 commit 353f9aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 9 additions & 9 deletions server/routes/server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ router.get('/signup', (req, res) => {

router.get('/projects/:project_id', async (req, res) => {
const exists = await projectExists(req.params.project_id);
sendHtml(req, res, exists);
await sendHtml(req, res, exists);
});

router.get(
Expand All @@ -39,7 +39,7 @@ router.get(
req.params.username,
req.params.project_id
);
sendHtml(req, res, exists);
await sendHtml(req, res, exists);
}
);

Expand All @@ -52,26 +52,26 @@ router.get('/:username/sketches/:project_id', async (req, res) => {
if (project.exists) {
res.send(renderProjectIndex(req.params.username, project.userProject.name));
} else {
sendHtml(req, res, project.exists);
await sendHtml(req, res, project.exists);
}
});

router.get('/:username/sketches', async (req, res) => {
const exists = await userExists(req.params.username);
sendHtml(req, res, exists);
await sendHtml(req, res, exists);
});

router.get('/:username/full/:project_id', async (req, res) => {
const exists = await projectForUserExists(
req.params.username,
req.params.project_id
);
sendHtml(req, res, exists);
await sendHtml(req, res, exists);
});

router.get('/full/:project_id', async (req, res) => {
const exists = await projectExists(req.params.project_id);
sendHtml(req, res, exists);
await sendHtml(req, res, exists);
});

router.get('/login', (req, res) => {
Expand Down Expand Up @@ -119,7 +119,7 @@ router.get('/:username/assets', async (req, res) => {
const exists = await userExists(req.params.username);
const isLoggedInUser = req.user && req.user.username === req.params.username;
const canAccess = exists && isLoggedInUser;
sendHtml(req, res, canAccess);
await sendHtml(req, res, canAccess);
});

router.get('/account', (req, res) => {
Expand All @@ -139,12 +139,12 @@ router.get('/:username/collections/:id', async (req, res) => {
req.params.username,
req.params.id
);
sendHtml(req, res, exists);
await sendHtml(req, res, exists);
});

router.get('/:username/collections', async (req, res) => {
const exists = await userExists(req.params.username);
sendHtml(req, res, exists);
await sendHtml(req, res, exists);
});

router.get('/privacy-policy', (req, res) => {
Expand Down
5 changes: 3 additions & 2 deletions server/views/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ export function renderProjectIndex(username, projectName) {
* @param {import('express').e.Response} res
* @param {boolean} [exists]
*/
export default function sendHtml(req, res, exists = true) {
export default async function sendHtml(req, res, exists = true) {
if (!exists) {
res.status(404);
get404Sketch((html) => res.send(html));
const html = await get404Sketch();
res.send(html);
} else {
res.send(renderIndex());
}
Expand Down

0 comments on commit 353f9aa

Please sign in to comment.