-
Notifications
You must be signed in to change notification settings - Fork 3
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
Slight improvement: validate configuration #113
base: master
Are you sure you want to change the base?
Changes from all commits
8758029
a5a5a73
b3bc7e9
7b2b940
25c9936
86cb467
12b10db
7d0cf33
8162af3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
{ | ||
} | ||
"printWidth": 80 | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import jwt from "jsonwebtoken"; | ||
import { jwtConfig } from "../../../config"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to stick with the approach of importing what we need for config values! |
||
import { config } from "../../../config"; | ||
import { getUserByEmail, hashPassword } from "../../../models/users"; | ||
|
||
/* | ||
|
@@ -39,9 +39,9 @@ export async function getToken(req, res) { | |
const payload = { | ||
userEmail: user.email, | ||
}; | ||
const token = jwt.sign(payload, jwtConfig.jwtSecret, { | ||
const token = jwt.sign(payload, config.jwtConfig.jwtSecret, { | ||
algorithm: "HS256", | ||
expiresIn: jwtConfig.jwtTokenExpiry, | ||
expiresIn: config.jwtConfig.jwtTokenExpiry, | ||
}); | ||
|
||
return res.json({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,49 +6,53 @@ import jwt from "express-jwt"; | |
import http from "http"; | ||
import morgan from "morgan"; | ||
import api from "./api"; | ||
import config from "./config"; | ||
import reminderScheduler from './services/scheduler' | ||
|
||
let app = express(); | ||
app.server = http.createServer(app); | ||
|
||
// logger | ||
app.use(morgan("dev")); | ||
|
||
// 3rd party middleware | ||
app.use( | ||
cors({ | ||
exposedHeaders: config.corsHeaders, | ||
}) | ||
); | ||
|
||
app.use(bodyParser.urlencoded({ extended: true })); | ||
|
||
app.use( | ||
bodyParser.json({ | ||
limit: config.bodyLimit, | ||
}) | ||
); | ||
|
||
reminderScheduler.start(); | ||
|
||
app.use( | ||
jwt({ | ||
secret: config.jwtConfig.jwtSecret, | ||
algorithms: ["HS256"], | ||
}).unless({ | ||
path: [ | ||
"/api/twilio/reply", // Authentication handled by Twilio middleware | ||
"/api/ping", // Open health check | ||
"/api/auth", // Used to login | ||
], | ||
}) | ||
); | ||
|
||
app.use("/api", api({ config })); | ||
|
||
app.server.listen(config.port, () => { | ||
console.log(`Started on port ${app.server.address().port}`); | ||
}); | ||
|
||
export default app; | ||
import { config, validateConfig } from "./config"; | ||
import reminderScheduler from "./services/scheduler"; | ||
|
||
class Application { | ||
constructor() { | ||
this.app = express(); | ||
} | ||
|
||
start() { | ||
validateConfig(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will display the config error and won't start but do we want it to be because of the exception or because of the error? For example, if you add a try/catch block around validate config you would see
where right now we see:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we add |
||
|
||
this.app.server = http.createServer(this.app); | ||
this.app.use(morgan("dev")); | ||
// 3rd party middleware | ||
this.app.use(cors({ exposedHeaders: config.corsHeaders })); | ||
this.app.use(bodyParser.urlencoded({ extended: true })); | ||
this.app.use(bodyParser.json({ limit: config.bodyLimit })); | ||
|
||
// logger | ||
|
||
reminderScheduler.start(); | ||
|
||
this.app.use( | ||
jwt({ secret: config.jwtConfig.jwtSecret, algorithms: ["HS256"] }).unless( | ||
{ | ||
path: [ | ||
"/api/twilio/reply", // Authentication handled by Twilio middleware | ||
"/api/ping", // Open health check | ||
"/api/auth", // Used to login | ||
], | ||
} | ||
) | ||
); | ||
|
||
this.app.use("/api", api({ config })); | ||
|
||
this.app.server.listen(config.port, () => { | ||
console.log(`Started on port ${this.app.server.address().port}`); | ||
}); | ||
} | ||
|
||
stop() { | ||
this.app.server.close(); | ||
} | ||
} | ||
|
||
const application = new Application(); | ||
application.start(); | ||
|
||
export default application; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure the linting is handling this correctly but generally we have tried to do one new line per chained call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was for the linter. The
printWidth
property. It wasn't there.I just added it.
So yeah now it's breaking down the chain calls to multiple lines if it's more than 80 chars.