Skip to content

Commit de00985

Browse files
authored
fix(deploy-web): refactor user pages + bring back to pages router from app router (#169)
1 parent e93864a commit de00985

File tree

194 files changed

+2975
-4170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+2975
-4170
lines changed

api/src/caching/helpers.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ export const Memoize = (options?: MemoizeOptions) => (target: object, propertyNa
2929
export async function cacheResponse<T>(seconds: number, key: string, refreshRequest: () => Promise<T>, keepData?: boolean): Promise<T> {
3030
const duration = seconds * 1000;
3131
const cachedObject = cacheEngine.getFromCache(key) as CachedObject<T> | undefined;
32-
console.log(`Cache key: ${key}`);
32+
// console.log(`Cache key: ${key}`);
3333

3434
// If first time or expired, must refresh data if not already refreshing
3535
const cacheExpired = Math.abs(differenceInSeconds(cachedObject?.date, new Date())) > seconds;
3636
if ((!cachedObject || cacheExpired) && !(key in pendingRequests)) {
37-
console.log(`Making request: ${key}`);
37+
// console.log(`Making request: ${key}`);
3838
pendingRequests[key] = refreshRequest()
3939
.then((data) => {
4040
cacheEngine.storeInCache(key, { date: new Date(), data: data }, keepData ? undefined : duration);
4141
return data;
4242
})
4343
.catch((err) => {
44-
console.log(`Error making cache request ${err}`);
44+
// console.log(`Error making cache request ${err}`);
4545
Sentry.captureException(err);
4646
})
4747
.finally(() => {
@@ -51,10 +51,10 @@ export async function cacheResponse<T>(seconds: number, key: string, refreshRequ
5151

5252
// If there is data in cache, return it even if it is expired. Otherwise, wait for the refresh request to finish
5353
if (cachedObject) {
54-
console.log(`Cache hit: ${key}`);
54+
// console.log(`Cache hit: ${key}`);
5555
return cachedObject.data;
5656
} else {
57-
console.log(`Waiting for pending request: ${key}`);
57+
// console.log(`Waiting for pending request: ${key}`);
5858
return (await pendingRequests[key]) as T;
5959
}
6060
}

api/src/middlewares/userMiddleware.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ export const kvStore = {
2121

2222
export const requiredUserMiddleware = verifyRsaJwt({
2323
jwksUri: env.Auth0JWKSUri,
24-
kvStore: kvStore,
25-
verbose: true
24+
kvStore: kvStore
2625
});
2726

2827
export const optionalUserMiddleware = verifyRsaJwt({

api/src/routers/userRouter.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const userRequiredRouter = new Hono();
3030
userRequiredRouter.use("*", requiredUserMiddleware);
3131

3232
const userOptionalRouter = new Hono();
33-
userRequiredRouter.use("*", optionalUserMiddleware);
33+
userOptionalRouter.use("*", optionalUserMiddleware);
3434

3535
userRequiredRouter.post("/manage-subscription", async (c) => {
3636
const userId = getCurrentUserId(c);
@@ -139,7 +139,6 @@ userOptionalRouter.get("/template/:id", async (c) => {
139139

140140
if (!uuid.validate(templateId)) {
141141
return c.text("Invalid template id", 400);
142-
return;
143142
}
144143

145144
const template = await getTemplateById(templateId, userId);

api/src/services/db/templateService.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export async function saveTemplate(
6767
) {
6868
let template = await Template.findOne({
6969
where: {
70-
id: id,
70+
id: id || null,
7171
userId: userId
7272
}
7373
});

api/src/verify-rsa-jwt-cloudflare-worker-main/hono-middleware.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { Context, MiddlewareHandler } from 'hono';
2-
import type { GeneralKeyValueStore, VerificationResult } from '.';
3-
import { getJwks, useKVStore, verify } from '.';
1+
import type { Context, MiddlewareHandler } from "hono";
2+
import type { GeneralKeyValueStore, VerificationResult } from ".";
3+
import { getJwks, useKVStore, verify } from ".";
44

55
export type VerifyRsaJwtConfig = {
66
jwksUri?: string;
@@ -10,25 +10,24 @@ export type VerifyRsaJwtConfig = {
1010
optional?: boolean;
1111
};
1212

13-
const PAYLOAD_KEY = 'verifyRsaJwtPayload';
13+
const PAYLOAD_KEY = "verifyRsaJwtPayload";
1414

1515
export function verifyRsaJwt(config?: VerifyRsaJwtConfig): MiddlewareHandler {
1616
return async (ctx: Context, next) => {
17-
const jwtToken = ctx.req.headers
18-
.get('Authorization')
19-
?.replace(/Bearer\s+/i, '');
20-
if (!jwtToken || jwtToken.length === 0) {
21-
return new Response('Bad Request', { status: 400 });
22-
}
2317
try {
18+
const jwtToken = ctx.req.headers.get("Authorization")?.replace(/Bearer\s+/i, "");
19+
if (!jwtToken || jwtToken.length === 0) {
20+
throw new Error("JWT token not found in Authorization header");
21+
}
22+
2423
const jwks = await getJwks(
2524
config?.jwksUri || ctx.env.JWKS_URI,
2625
useKVStore(config?.kvStore || ctx.env?.VERIFY_RSA_JWT),
27-
ctx.env?.VERIFY_RSA_JWT_JWKS_CACHE_KEY,
26+
ctx.env?.VERIFY_RSA_JWT_JWKS_CACHE_KEY
2827
);
2928
const result = await verify(jwtToken, jwks);
3029
if (result.payload === null) {
31-
throw new Error('Invalid token');
30+
throw new Error("Invalid token");
3231
}
3332

3433
// Custom validator that should throw an error if the payload is invalid.
@@ -38,8 +37,7 @@ export function verifyRsaJwt(config?: VerifyRsaJwtConfig): MiddlewareHandler {
3837
ctx.set(PAYLOAD_KEY, result.payload);
3938
await next();
4039
} catch (error) {
41-
config?.verbose &&
42-
console.error({ message: 'verification failed', error });
40+
config?.verbose && console.error({ message: "verification failed", error });
4341

4442
if (config?.optional) {
4543
await next();

api/webpack.dev.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ module.exports = {
88
entry: "./src/index.ts",
99
mode: NODE_ENV,
1010
target: "node",
11+
devtool: "source-map",
1112
output: {
1213
path: path.resolve(__dirname, "dist"),
13-
filename: "server.js",
14+
filename: "server.js"
1415
},
1516
resolve: {
1617
extensions: [".ts", ".js"],
17-
alias: hq.get("webpack"),
18+
alias: hq.get("webpack")
1819
},
1920
externals: [nodeExternals()],
2021
module: {
@@ -23,9 +24,9 @@ module.exports = {
2324
test: /\.(ts|js)x?$/,
2425
exclude: /node_modules/,
2526
loader: "ts-loader",
26-
options: { configFile: "tsconfig.build.json"}
27-
},
28-
],
27+
options: { configFile: "tsconfig.build.json" }
28+
}
29+
]
2930
},
30-
plugins: [new NodemonPlugin()],
31+
plugins: [new NodemonPlugin()]
3132
};

api/webpack.prod.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const path = require("path");
22
const { NODE_ENV = "production" } = process.env;
3-
const NodemonPlugin = require("nodemon-webpack-plugin");
43
const nodeExternals = require("webpack-node-externals");
54
const hq = require("alias-hq");
65

@@ -10,11 +9,11 @@ module.exports = {
109
target: "node",
1110
output: {
1211
path: path.resolve(__dirname, "dist"),
13-
filename: "server.js",
12+
filename: "server.js"
1413
},
1514
resolve: {
1615
extensions: [".ts", ".js"],
17-
alias: hq.get("webpack"),
16+
alias: hq.get("webpack")
1817
},
1918
externals: [nodeExternals()],
2019
module: {
@@ -23,9 +22,9 @@ module.exports = {
2322
test: /\.(ts|js)x?$/,
2423
exclude: /node_modules/,
2524
loader: "ts-loader",
26-
options: { configFile: "tsconfig.build.json"}
27-
},
28-
],
25+
options: { configFile: "tsconfig.build.json" }
26+
}
27+
]
2928
},
30-
plugins: [new NodemonPlugin()],
29+
plugins: []
3130
};

deploy-web/next-env.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
/// <reference types="next/navigation-types/compat/navigation" />
43

54
// NOTE: This file should not be edited
65
// see https://nextjs.org/docs/basic-features/typescript for more information.

deploy-web/next.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const moduleExports = {
2525
typescript: {
2626
tsconfigPath: "./tsconfig.json"
2727
},
28+
transpilePackages: ["geist"],
2829
// experimental: {
2930
// // outputStandalone: true,
3031
// externalDir: true // to make the import from shared parent folder work https://github.com/vercel/next.js/issues/9474#issuecomment-810212174

0 commit comments

Comments
 (0)