Skip to content

Commit

Permalink
Don't require self in package.json (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgachnang authored Jan 7, 2022
1 parent e7ee066 commit 054e7ca
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 215 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"mongoose": "^6.0.8",
"mongoose-rest-framework": "^0.1.1",
"on-finished": "^2.3.0",
"passport": "^0.5.0",
"passport-anonymous": "^1.0.1",
Expand Down
31 changes: 18 additions & 13 deletions src/expressServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import {Env, setupAuth, UserModel} from "./mongooseRestFramework";
const SLOW_READ_MAX = 200;
const SLOW_WRITE_MAX = 500;

const dsn = (process.env as Env).SENTRY_DSN;
if (process.env.NODE_ENV === "production") {
if (!dsn) {
throw new Error("You must set SENTRY_DSN in the environment.");
export function setupErrorLogging() {
const dsn = (process.env as Env).SENTRY_DSN;
if (process.env.NODE_ENV === "production") {
if (!dsn) {
throw new Error("You must set SENTRY_DSN in the environment.");
}
Sentry.init({dsn});
}
Sentry.init({dsn});
}

export type AddRoutes = (router: Router) => void;
Expand Down Expand Up @@ -245,6 +247,7 @@ export interface SetupServerOptions {
userModel: UserModel;
addRoutes: AddRoutes;
loggingOptions?: LoggingOptions;
skipListen?: boolean;
}

// Sets up the routes and returns a function to launch the API.
Expand All @@ -262,14 +265,16 @@ export function setupServer(options: SetupServerOptions) {
throw e;
}

const port = process.env.PORT || "9000";
try {
app.listen(port, () => {
logger.info(`Listening at on port ${port}`);
});
} catch (err) {
logger.error(`Error trying to start HTTP server: ${err}\n${(err as any).stack}`);
process.exit(1);
if (!options.skipListen) {
const port = process.env.PORT || "9000";
try {
app.listen(port, () => {
logger.info(`Listening at on port ${port}`);
});
} catch (err) {
logger.error(`Error trying to start HTTP server: ${err}\n${(err as any).stack}`);
process.exit(1);
}
}
return app;
}
Expand Down
Loading

0 comments on commit 054e7ca

Please sign in to comment.