Skip to content

Commit 85e759d

Browse files
committed
fix linting
1 parent 5d09d40 commit 85e759d

File tree

15 files changed

+397
-3958
lines changed

15 files changed

+397
-3958
lines changed

.eslintrc

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
{
2-
"extends": ["airbnb-base", "plugin:prettier/recommended", "esnext"],
3-
"parserOptions": {
4-
"parser": "@typescript-eslint/parser"
2+
"extends": ["airbnb-base", "plugin:prettier/recommended", "plugin:@typescript-eslint/recommended"],
3+
"plugins": ["import"],
4+
"rules": {
5+
// turn on errors for missing imports
6+
"import/no-unresolved": "error",
7+
"import/extensions": [
8+
"error",
9+
"ignorePackages",
10+
{
11+
"js": "never",
12+
"jsx": "never",
13+
"ts": "never",
14+
"tsx": "never"
515
}
6-
}
16+
],
17+
"no-unused-vars": "off",
18+
"max-classes-per-file": "off",
19+
"func-names": "off",
20+
"@typescript-eslint/no-unused-vars": [
21+
"warn", // or "error"
22+
{
23+
"argsIgnorePattern": "^_",
24+
"varsIgnorePattern": "^_",
25+
"caughtErrorsIgnorePattern": "^_"
26+
}
27+
]
28+
},
29+
"settings": {
30+
"import/parsers": {
31+
"@typescript-eslint/parser": [".ts", ".tsx", ".js", ".jsx"]
32+
},
33+
"import/resolver": {
34+
"typescript": {
35+
"alwaysTryTypes": true
36+
}
37+
}
38+
}
39+
}

dist/index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
/* eslint import/no-nodejs-modules: ["error", {"allow": ["crypto"]}] */
12
import { randomUUID } from "crypto";
23
import fastify from "fastify";
4+
import { fastifyAuthPlugin } from "./plugins/auth.js";
5+
import FastifyAuthProvider from '@fastify/auth';
6+
import { EventsApiRoles } from "./roles.js";
37
const now = () => Date.now();
4-
function init() {
8+
async function init() {
59
const app = fastify({
610
logger: true,
711
disableRequestLogging: true,
@@ -15,6 +19,9 @@ function init() {
1519
return event.requestContext.requestId;
1620
},
1721
});
22+
await app.register(fastifyAuthPlugin);
23+
await app.register(FastifyAuthProvider);
24+
app.runEnvironment = process.env.RunEnvironment ?? 'dev';
1825
app.addHook("onRequest", (req, _, done) => {
1926
req.startTime = now();
2027
req.log.info({ url: req.raw.url }, "received request");
@@ -29,10 +36,22 @@ function init() {
2936
done();
3037
});
3138
app.get("/api/v1/healthz", (_, reply) => reply.send({ message: "UP" }));
39+
app.get("/api/v1/protected", async (_, reply) => {
40+
app.auth([
41+
app.authenticate,
42+
async (request, reply) => {
43+
await app.authorize(request, reply, [EventsApiRoles.MANAGER]);
44+
}
45+
]);
46+
reply.send({ message: "UP" });
47+
});
3248
return app;
3349
}
3450
if (import.meta.url === `file://${process.argv[1]}`) {
35-
init().listen({ port: 3000 }, (err) => {
51+
// local development
52+
const app = await init();
53+
app.listen({ port: 3000 }, (err) => {
54+
/* eslint no-console: ["error", {"allow": ["log", "error"]}] */
3655
if (err)
3756
console.error(err);
3857
console.log("Server listening on 3000");

dist/lambda.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
/* eslint-disable */
12
import awsLambdaFastify from "@fastify/aws-lambda";
23
import init from "./index.js";
3-
const app = init();
4+
const app = await init();
45
const handler = awsLambdaFastify(app, {
56
decorateRequest: false,
67
serializeLambdaArguments: true,
78
});
8-
await app.ready();
9+
await app.ready(); // needs to be placed after awsLambdaFastify call because of the decoration: https://github.com/fastify/aws-lambda-fastify/blob/master/index.js#L9
910
export { handler };

0 commit comments

Comments
 (0)