Skip to content
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

fix: log process exit, auto restart docker #113

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ RUN yarn workspaces foreach -p run build

# Production image, copy all the files and run next
FROM node:18-alpine AS runner
RUN apk add --no-cache parallel
WORKDIR /app

ENV NODE_ENV production
Expand All @@ -41,4 +42,4 @@ COPY --from=builder /app/. .

EXPOSE 5000
EXPOSE 3000
CMD yarn workspace server start & yarn workspace ui start
CMD parallel --ungroup --halt-on-error 2 ::: "yarn workspace server start" "yarn workspace ui start"
2 changes: 1 addition & 1 deletion server/public/files/departements_academies_regions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Occitanie;16;76;081;Toulouse;Tarn
Occitanie;16;76;082;Toulouse;Tarn-et-Garonne
Provence-Alpes-Côte d'Azur;23;93;083;Nice;Var
Provence-Alpes-Côte d'Azur;02;93;084;Aix-Marseille;Vaucluse
Pays de la Loire;17;52;085;Nantes;Vandée
Pays de la Loire;17;52;085;Nantes;Vendée
Nouvelle-Aquitaine;13;75;086;Poitiers;Vienne
Nouvelle-Aquitaine;22;75;087;Limoges;Haute-Vienne
Grand Est;12;44;088;Nancy-Metz;Vosges
Expand Down
13 changes: 8 additions & 5 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { extractUserInRequest, registerCoreModule } from "./modules/core";
import { registerFormationModule } from "./modules/data/index";
import { registerIntentionsModule } from "./modules/intentions/index";
import { server } from "./server";

server.register(fastifyCors, {});

server.register(fastifySwagger, {
Expand Down Expand Up @@ -67,6 +66,10 @@ server.setErrorHandler((error, _, reply) => {
reply.status(500).send({ error: "internal error", statusCode: 500 });
});

process.on("uncaughtExceptionMonitor", (error, origin) => {
logger.error("error: process exit", { error, origin });
});

server.addHook("onRequest", extractUserInRequest);
server.register(loggerContextPlugin);

Expand All @@ -79,12 +82,12 @@ server.register(
{ prefix: "/api" }
);

const cb = (err: Error | null) => {
if (err) {
console.log(err);
const cb = (error: Error | null) => {
if (error) {
logger.error("server failed to start", { error });
process.exit(1);
} else {
console.log("server listening");
logger.info("server started");
}
};

Expand Down