From d40b9bc2e067b159da76fa02e5da437540556c45 Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 14 Nov 2018 22:53:26 -0400 Subject: "return page()" instead of "await page(); return" No need for the await when we always do return immediately after anyway. --- index.js | 54 +++++++++++++++--------------------------------------- 1 file changed, 15 insertions(+), 39 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 488ce6c..576a5a8 100755 --- a/index.js +++ b/index.js @@ -254,7 +254,7 @@ const handleRequest = async (request, response) => { if (compareArr(urlParts, ['login'])) { if (request.method === 'GET') { - await page(request, response, fixWS` + return page(request, response, fixWS`

Login

@@ -264,8 +264,6 @@ const handleRequest = async (request, response) => {

`) - - return } else if (request.method === 'POST') { const { username, token, sessionid, csrftoken } = await getData(request) @@ -278,25 +276,21 @@ const handleRequest = async (request, response) => { request.headers.cookie = response.getHeader('Set-Cookie').join(';') // Cheating! To make the header show right. - await page(request, response, fixWS` + return page(request, response, fixWS`

Okay, you're logged in.

`) - - return } } if (compareArr(urlParts, ['logout'])) { if (request.method === 'GET') { - await page(request, response, fixWS` + return page(request, response, fixWS`

Log Out

Are you sure you want to log out?

`) - - return } else if (request.method === 'POST') { const { username, token, sessionid, csrftoken } = await getData(request) @@ -305,21 +299,17 @@ const handleRequest = async (request, response) => { request.headers.cookie = '' // Cheating, kind of, but to make the header print right :) response.setHeader('Set-Cookie', ['username', 'token', 'sessionid', 'csrftoken'].map(clearCookie)) - await page(request, response, fixWS` + return page(request, response, fixWS`

Okay, you've been logged out.

`) - - return } } if (compareArr(urlParts, ['notifications'])) { if (!cookie.username) { - await page(request, response, fixWS` + return page(request, response, fixWS`

Sorry, you can't view your notifications until you've logged in.

`) - - return } const notifications = await getNotifications(cookie.username, cookie.token, pageNumber) @@ -348,15 +338,13 @@ const handleRequest = async (request, response) => { ` - await page(request, response, fixWS` + return page(request, response, fixWS`

Notifications

${listText}

You are on page ${pageNumber}. ${notifications.length === limit && `Next`} ${pageNumber > 1 && `Previous`}

`) - - return } if (compareArr(urlParts, ['notifications', 'mark-as-read'])) { @@ -378,10 +366,9 @@ const handleRequest = async (request, response) => { const project = await getProject(projectID, cookie.token) if (project.code === 'NotFound') { - await page(request, response, fixWS` - Sorry, that project either doesn't exist or isn't shared. + return page(request, response, fixWS` + 404. Sorry, that project either doesn't exist or isn't shared. `) - return } if (urlParts.length === 2) { @@ -398,7 +385,7 @@ const handleRequest = async (request, response) => { const remixes = await fetch(`https://api.scratch.mit.edu/projects/${projectID}/remixes?limit=5`).then(res => res.json()) const remixesText = remixes.map(templates.projectThumbnail).join('\n') - await page(request, response, fixWS` + return page(request, response, fixWS`

${project.title}

Created by ${templates.user(project.author.username)}.${parentProjectText}

The thumbnail for this project

@@ -424,15 +411,11 @@ const handleRequest = async (request, response) => {

See all!

` : ''} `) - - return } else if (compareArr(urlParts.slice(2), ['remixes'])) { - await page(request, response, fixWS` + return page(request, response, fixWS`

Remixes of ${filterHTML(project.title)}

${await templates.projectList(`https://api.scratch.mit.edu/projects/${projectID}/remixes`, pathname, pageNumber)} `) - - return } } @@ -441,17 +424,16 @@ const handleRequest = async (request, response) => { const user = await getUser(username) if (user.code === 'NotFound') { - await page(request, response, fixWS` + return page(request, response, fixWS` 404. Sorry, that user doesn't exist. `) - return } if (urlParts.length === 2) { const projects = await fetch(`https://api.scratch.mit.edu/users/${username}/projects?limit=5`).then(res => res.json()) const projectsText = projects.map(templates.projectThumbnail).join('\n') - await page(request, response, fixWS` + return page(request, response, fixWS`

This user's profile picture ${user.username}

${user.profile.bio ? fixWS`

About Me

@@ -471,15 +453,11 @@ const handleRequest = async (request, response) => {

See all!

`) - - return } else if (compareArr(urlParts.slice(2), ['projects'])) { - await page(request, response, fixWS` + return page(request, response, fixWS`

${user.username}'s projects

${await templates.projectList(`https://api.scratch.mit.edu/users/${username}/projects`, pathname, pageNumber)} `) - - return } } @@ -494,14 +472,12 @@ const handleRequest = async (request, response) => { } if (urlParts.length === 0) { - await page(request, response, fixWS` + return page(request, response, fixWS` You are at the homepage. Sorry, I haven't implmented any content for it yet. `) - - return } - await page(request, response, fixWS` + return page(request, response, fixWS` 404. Sorry, I'm not sure where you are right now. `) } -- cgit 1.3.0-6-gf8a5