Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

119 missing return statement in pages api handlers #120

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# production
/build
/dist

# misc
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile → Dockerfile.frontend
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN yarn install --frozen-lockfile --production=false
COPY --link . .

# Build application
RUN yarn run build
RUN yarn run build:frontend

# Remove development dependencies
RUN yarn install --production=true
Expand Down
55 changes: 55 additions & 0 deletions Dockerfile.mail
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=20.11.1
FROM node:${NODE_VERSION}-slim as base

# App lives here
WORKDIR /app

# Set production environment
ENV NODE_ENV="production"
ARG YARN_VERSION=1.22.21
RUN npm install -g yarn@$YARN_VERSION --force


# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential node-gyp pkg-config python-is-python3

# Install node modules
COPY --link package.json yarn.lock ./
RUN yarn install --frozen-lockfile --production=false

# Copy application code
COPY --link . .

# Build application
RUN yarn run build:mail

# Remove development dependencies
RUN yarn install --production=true


# Final stage for app image
FROM base

ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# Copy built application
COPY --from=build /app /app

RUN chown -R nextjs:nodejs /app

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000

USER nextjs


CMD [ "node", "dist/mail-server/index.js" ]
20 changes: 20 additions & 0 deletions mail-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const path = require("path");
const dotenv = require("dotenv");
dotenv.config({
path: path.resolve(process.cwd(), process.env.NODE_ENV === "production" ? ".env.production" : ".env.local"),
});
const { startMailServiceCron } = require("./src/server/mail-service/mail-cron");
const verifyEnvironmentVariables = require("./src/server/utils/verifyEnvironmentVariables");

(async () => {

const { isVerified, envVariablesStatus } = await verifyEnvironmentVariables();

console.log("Environment variables status", envVariablesStatus);
if (isVerified) {
startMailServiceCron();
} else {
console.error("Mail service cron not started");
}

})();
11 changes: 11 additions & 0 deletions mail-server.webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const path = require('path');

module.exports = {
target: 'node',
entry: './mail-server.js',
mode: 'production',
output: {
filename: 'index.js',
path: path.resolve(__dirname, 'dist/mail-server'),
},
};
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "nodemon server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js",
"dev": "concurrently \"npm run dev:frontend\" \"npm run dev:mail\"",
"build": "concurrently \"npm run build:frontend\" \"npm run build:mail\"",
"build:frontend": "next build",
"build:mail": "webpack --config mail-server.webpack.config.js",
"start": "concurrently \"npm run start:frontend\" \"npm run start:mail\"",
"lint": "next lint",
"format:check": "prettier --check --ignore-path .prettierignore .",
"format:fix": "prettier --write --ignore-path .gitignore .",
"find:unused": "next-unused"
"find:unused": "next-unused",
"dev:frontend": "nodemon server.js",
"dev:mail": "nodemon mail-server.js",
"start:frontend": "NODE_ENV=production node server.js",
"start:mail": "NODE_ENV=production node dist/mail-server/index.js",
"docker:frontend": "docker build -t sharmaamits/saasbuilder -f Dockerfile.frontend --platform linux/amd64 .",
"docker:mail": "docker build -t sharmaamits/saasbuilder-mail -f Dockerfile.mail --platform linux/amd64 ."
},
"dependencies": {
"@curvenote/ansi-to-react": "^7.0.0",
Expand Down Expand Up @@ -54,10 +62,13 @@
"sass": "^1.56.1",
"sharp": "0.32.6",
"swagger-ui-react": "^5.4.2",
"webpack": "^5.91.0",
"webpack-cli": "^5.1.4",
"yup": "^0.32.11"
},
"devDependencies": {
"@flydotio/dockerfile": "^0.5.2",
"concurrently": "^8.2.2",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-react": "^7.33.2",
Expand Down
6 changes: 3 additions & 3 deletions pages/api/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ export default async function handleAction(nextRequest, nextResponse) {
.setHeader("content-type", response.headers["content-type"])
.send(data);
}
if (data) nextResponse.send({ ...data });
else nextResponse.send();
if (data) return nextResponse.send({ ...data });
else return nextResponse.send();
}
} catch (error) {
console.error("Action Route error", error?.response?.data);
const errorCode = error?.response?.status || 500;
const errorMessage =
error?.response?.data?.message || defaultErrorMessage;
nextResponse.status(errorCode).send({
return nextResponse.status(errorCode).send({
message: errorMessage,
});
}
Expand Down
8 changes: 4 additions & 4 deletions pages/api/provider-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ export default async function handleGetProviderDetails(
const response = await getProviderOrgDetails();

const faviconURL = response?.data?.orgFavIconURL;
nextResponse.status(200).send({ providerOrgFaviconURL: faviconURL });
return nextResponse.status(200).send({ providerOrgFaviconURL: faviconURL });
} catch (error) {
let defaultErrorMessage = "Something went wrong. Please retry";

if (
error.name === "ProviderAuthError" ||
error?.response?.status === undefined
) {
nextResponse.status(500).send({
return nextResponse.status(500).send({
message: defaultErrorMessage,
});
} else {
nextResponse.status(error.response?.status || 500).send({
return nextResponse.status(error.response?.status || 500).send({
message: error.response?.data?.message || defaultErrorMessage,
});
}
}
} else {
nextResponse.status(404).json({
return nextResponse.status(404).json({
message: "Endpoint not found",
});
}
Expand Down
10 changes: 5 additions & 5 deletions pages/api/reset-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ export default async function handleResetPassword(nextRequest, nextResponse) {
if (nextRequest.method === "POST") {
try {
const response = await customerUserResetPassword(nextRequest.body);
nextResponse.status(200).send();
return nextResponse.status(200).send();
} catch (error) {
let defaultErrorMessage = "Something went wrong. Please retry";

if (
error.name === "ProviderAuthError" ||
error?.response?.status === undefined
) {
nextResponse.status(500).send({
return nextResponse.status(500).send({
message: defaultErrorMessage,
});
} else {
let responseErrorMessage = error.response?.data?.message;

if (responseErrorMessage === "user not found: record not found") {
nextResponse.status(200).send()
return nextResponse.status(200).send()
}

nextResponse.status(error.response?.status || 500).send({
return nextResponse.status(error.response?.status || 500).send({
message: responseErrorMessage || defaultErrorMessage,
});
}
}
} else {
nextResponse.status(404).json({
return nextResponse.status(404).json({
message: "Endpoint not found",
});
}
Expand Down
10 changes: 5 additions & 5 deletions pages/api/signin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default async function handleSignIn(nextRequest, nextResponse) {
if (nextRequest.method === "POST") {
try {
const response = await customerUserSignIn(nextRequest.body);
nextResponse.status(200).send({ ...response.data });
return nextResponse.status(200).send({ ...response.data });
} catch (error) {
let defaultErrorMessage =
"Failed to sign in. Either the credentials are incorrect or the user does not exist";
Expand All @@ -13,23 +13,23 @@ export default async function handleSignIn(nextRequest, nextResponse) {
error.name === "ProviderAuthError" ||
error?.response?.status === undefined
) {
nextResponse.status(500).send({
return nextResponse.status(500).send({
message: defaultErrorMessage,
});
} else if (
error.response?.data?.message === "wrong user email or password"
) {
nextResponse.status(400).send({
return nextResponse.status(400).send({
message: defaultErrorMessage,
});
} else {
nextResponse.status(error.response?.status || 500).send({
return nextResponse.status(error.response?.status || 500).send({
message: error.response?.data?.message || defaultErrorMessage,
});
}
}
} else {
nextResponse.status(404).json({
return nextResponse.status(404).json({
message: "Endpoint not found",
});
}
Expand Down
10 changes: 5 additions & 5 deletions pages/api/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default async function handleSignup(nextRequest, nextResponse) {
if (nextRequest.method === "POST") {
try {
const response = await customerUserSignUp(nextRequest.body);
nextResponse.status(200).send();
return nextResponse.status(200).send();
} catch (error) {
console.error(error?.response?.data);
let defaultErrorMessage = "Something went wrong. Please retry";
Expand All @@ -13,22 +13,22 @@ export default async function handleSignup(nextRequest, nextResponse) {
error.name === "ProviderAuthError" ||
error?.response?.status === undefined
) {
nextResponse.status(500).send({
return nextResponse.status(500).send({
message: defaultErrorMessage,
});
} else {
let responseErrorMessage = error.response?.data?.message;

if (responseErrorMessage === "tenant already exists") {
nextResponse.status(200).send();
return nextResponse.status(200).send();
}
nextResponse.status(error.response?.status || 500).send({
return nextResponse.status(error.response?.status || 500).send({
message: responseErrorMessage || defaultErrorMessage,
});
}
}
} else {
nextResponse.status(404).json({
return nextResponse.status(404).json({
message: "Endpoint not found",
});
}
Expand Down
Loading