Skip to content

Commit

Permalink
more improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cdleveille committed Jun 7, 2024
1 parent a1800c5 commit 3eaacfb
Show file tree
Hide file tree
Showing 9 changed files with 20,294 additions and 19,520 deletions.
19,496 changes: 0 additions & 19,496 deletions backups/2023-10-29_discs_backup.json

This file was deleted.

20,256 changes: 20,256 additions & 0 deletions backups/2024-06-07_discs_backup.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions src/controllers/bag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ export const initBagRoutes = (app: Elysia) => {
});

/* Get bag by id */
app.get("/bag/:id", async ({ request, params }) => {
app.get("/bag/:id", async ({ request, params: id }) => {
assertIsRequestAuthorized(request);
const { id } = params as Record<string, string>;
const bag = await Bag.findOne({ id }, projection);
if (!bag) throw new NotFoundError("Bag not found");
return bag;
Expand Down Expand Up @@ -89,9 +88,8 @@ export const initBagRoutes = (app: Elysia) => {
});

/* Delete bag (bearer auth secured) */
app.delete("/bag/delete/:id", async ({ request, params }) => {
app.delete("/bag/delete/:id", async ({ request, params: id }) => {
assertIsRequestAuthorized(request);
const { id } = params as Record<string, string>;
if (!id) throw new BadRequestError("Required path param missing: id");
const bag = await Bag.findOne({ id });
if (!bag) throw new NotFoundError("Bag not found");
Expand Down
6 changes: 2 additions & 4 deletions src/controllers/disc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export const initDiscRoutes = (app: Elysia) => {
});

/* Get disc by id */
app.get("/disc/:id", async ({ params }) => {
const { id } = params as Record<string, string>;
app.get("/disc/:id", async ({ params: id }) => {
const disc = await Disc.findOne({ id }, projection);
if (!disc) throw new NotFoundError("Disc not found");
return disc;
Expand All @@ -34,9 +33,8 @@ export const initDiscRoutes = (app: Elysia) => {
});

/* Delete disc by id (bearer auth secured) */
app.delete("/disc/:id", async ({ request, params }) => {
app.delete("/disc/:id", async ({ request, params: id }) => {
assertIsRequestAuthorized(request);
const { id } = params as Record<string, string>;
const disc = await Disc.findOne({ id });
if (!disc) throw new NotFoundError("Disc not found");
return Disc.deleteOne({ id });
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { connectToDatabase, log, startServer } from "@services";

try {
await connectToDatabase();
await startServer();
startServer();
} catch (error) {
log.error(error);
}
2 changes: 1 addition & 1 deletion src/middleware/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { log } from "@services";

export const useErrorHandler = (app: Elysia) => {
app.onError(({ error, request, path }) => {
const { message = error.toString() || "Internal server error", status = 500 } = error as {
const { message = error.toString() || "Internal Server Error", status = 500 } = error as {
message?: string;
status?: number;
};
Expand Down
30 changes: 29 additions & 1 deletion src/middleware/helmet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
import { Elysia } from "elysia";
import { helmet } from "elysia-helmet";

export const useHelmet = (app: Elysia) => app.use(helmet({ contentSecurityPolicy: false }));
export const useHelmet = (app: Elysia) =>
app.use(
helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
baseUri: ["'self'"],
childSrc: ["'self'"],
connectSrc: ["'self'"],
fontSrc: ["'self'", "https:", "data:"],
formAction: ["'self'"],
frameAncestors: ["'self'"],
frameSrc: ["'self'"],
imgSrc: ["'self'", "data:"],
manifestSrc: ["'self'"],
mediaSrc: ["'self'"],
objectSrc: ["'none'"],
scriptSrc: ["'self'"],
scriptSrcAttr: ["'none'"],
scriptSrcElem: ["'self'"],
styleSrc: ["'self'", "https:", "'unsafe-inline'"],
styleSrcAttr: ["none"],
styleSrcElem: ["'self'", "https:", "'unsafe-inline'"],
upgradeInsecureRequests: [],
workerSrc: ["'self'", "blob:"]
}
}
})
);
12 changes: 1 addition & 11 deletions src/middleware/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ export const useSwagger = (app: Elysia) =>
{ url: "http://localhost:5000", description: "development" }
]
},
exclude: [
"/",
"/docs",
"/docs/json",
"/bag",
"/bag/{id}",
"/bag/create",
"/bag/add-disc",
"/bag/remove-disc",
"/bag/delete/{id}"
]
exclude: ["/", /^\/(docs|bag)/i]
})
);
4 changes: 2 additions & 2 deletions src/services/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { Config } from "@helpers";
import { initMiddleware } from "@middleware";
import { log } from "@services";

export const startServer = async () => {
export const startServer = () => {
const app = new Elysia();
initMiddleware(app);
initRoutes(app);
app.listen(Config.PORT, () =>
log.info(
`Server started in ${Config.IS_PROD ? "production" : "development"} mode` +
`- running at ${app.server?.hostname}:${app.server?.port}.`
` - listening on port ${app.server.port}.`
)
);
};

0 comments on commit 3eaacfb

Please sign in to comment.