Skip to content

Commit 2e62ef1

Browse files
fix: fix awilix injection in production builds
1 parent ca2a96a commit 2e62ef1

15 files changed

Lines changed: 62 additions & 27 deletions

‎Dockerfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ WORKDIR /app
4242
# Set production environment
4343
ENV NODE_ENV=production
4444
ENV NEXT_TELEMETRY_DISABLED=1
45+
ENV NODE_OPTIONS=--enable-source-maps
4546

4647
# Create a non-root user
4748
RUN addgroup --system --gid 1001 nodejs
@@ -51,6 +52,7 @@ RUN adduser --system --uid 1001 nextjs
5152
COPY --from=builder /app/public ./public
5253
COPY --from=builder /app/.next/standalone ./
5354
COPY --from=builder /app/.next/static ./.next/static
55+
COPY --from=builder /app/.next/server ./.next/server
5456

5557
# Set correct permissions
5658
RUN chown -R nextjs:nodejs /app

‎docker-compose.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
REDIS_URL: "redis://:${REDIS_PASSWORD}@host.docker.internal:6379/0"
1212
MINIO_HOST: "host.docker.internal"
1313
FILES_BASE_URL: "http://host.docker.internal:9000"
14+
NODE_OPTIONS: "--enable-source-maps"
1415
extra_hosts:
1516
- "host.docker.internal:host-gateway"
1617
ports:

‎gen-pass.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
openssl rand -base64 12 | tr '+/' '-_'
1+
openssl rand -base64 12 | tr '+/' '-_'

‎next.config.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ import "./src/env.js";
88
const nextConfig = {
99
output: "standalone",
1010

11-
webpack(config) {
11+
webpack(config, { isServer, dev }) {
1212
const fileLoaderRule = config.module.rules.find((rule) =>
1313
rule.test?.test?.(".svg"),
1414
);
1515

16+
// Server-side sourcemaps for production Node stack traces
17+
if (!dev) {
18+
config.devtool = isServer ? "source-map" : "hidden-source-map";
19+
}
20+
1621
// Exclude svg from the default loader
1722
fileLoaderRule.exclude = /\.svg$/;
1823

‎src/server/api/di-container.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
asClass,
55
asValue,
66
createContainer,
7+
InjectionMode,
78
type AwilixContainer,
89
} from "awilix";
910
import type { Sql } from "postgres";
@@ -58,7 +59,9 @@ export type NeuronContainer = AwilixContainer<NeuronCradle>;
5859

5960
const createRootContainer = (): NeuronContainer => {
6061
const container = createContainer<NeuronCradle>({
61-
injectionMode: "CLASSIC",
62+
// PROXY is resilient to build-time minification (CLASSIC breaks when
63+
// constructor/function parameter names get mangled).
64+
injectionMode: InjectionMode.PROXY,
6265
strict: true,
6366
});
6467

‎src/server/db/cache.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type CacheClient = RedisClientType;
88
export function registerCacheClient(container: NeuronContainer) {
99
container.register({
1010
cacheClient: asFunction<CacheClient>(
11-
(env: typeof environment): CacheClient => {
11+
({ env }: { env: typeof environment }): CacheClient => {
1212
const g = globalThis as unknown as { __redis?: CacheClient };
1313

1414
// Reuse the dev client across HMR updates

‎src/server/services/cacheService.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class CacheService implements ICacheService {
3232
private singleObjectMemoryCache?: Map<string, string>; // key -> serialized string
3333
private groupObjectMemoryCache?: Map<string, Map<string, string>>; // group -> (key -> serialized string)
3434

35-
constructor(cacheClient: CacheClient) {
35+
constructor({ cacheClient }: { cacheClient: CacheClient }) {
3636
this.cacheClient = cacheClient;
3737
}
3838

‎src/server/services/emailService.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class EmailService implements IEmailService {
2020
private readonly transporter: Transporter;
2121
private readonly env: typeof environment;
2222

23-
constructor(env: typeof environment) {
23+
constructor({ env }: { env: typeof environment }) {
2424
this.env = env;
2525
this.transporter = nodemailer.createTransport({
2626
host: env.SMTP_HOST,

‎src/server/services/entity/classService.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,21 @@ export class ClassService implements IClassService {
6262
private readonly shiftService: IShiftService;
6363
private readonly imageService: IImageService;
6464

65-
constructor(
66-
db: Drizzle,
67-
userService: IUserService,
68-
volunteerService: IVolunteerService,
69-
termService: ITermService,
70-
shiftService: IShiftService,
71-
imageService: IImageService,
72-
) {
65+
constructor({
66+
db,
67+
userService,
68+
volunteerService,
69+
termService,
70+
shiftService,
71+
imageService,
72+
}: {
73+
db: Drizzle;
74+
userService: IUserService;
75+
volunteerService: IVolunteerService;
76+
termService: ITermService;
77+
shiftService: IShiftService;
78+
imageService: IImageService;
79+
}) {
7380
this.db = db;
7481
this.userService = userService;
7582
this.volunteerService = volunteerService;

‎src/server/services/entity/coverageService.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ export class CoverageService implements ICoverageService {
6262
private readonly volunteerService: IVolunteerService;
6363
private readonly shiftService: IShiftService;
6464

65-
constructor(
66-
db: Drizzle,
67-
volunteerService: IVolunteerService,
68-
shiftService: IShiftService,
69-
) {
65+
constructor({
66+
db,
67+
volunteerService,
68+
shiftService,
69+
}: {
70+
db: Drizzle;
71+
volunteerService: IVolunteerService;
72+
shiftService: IShiftService;
73+
}) {
7074
this.db = db;
7175
this.volunteerService = volunteerService;
7276
this.shiftService = shiftService;

0 commit comments

Comments
 (0)