Skip to content

Commit

Permalink
Not so fancy multistage ts build
Browse files Browse the repository at this point in the history
  • Loading branch information
xfenix committed Oct 17, 2023
1 parent 71825f9 commit ef12e17
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 33 deletions.
2 changes: 2 additions & 0 deletions back/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules/
build/
src/_tmp
.env
.DS_Store
*.lmdb*
Expand Down
9 changes: 7 additions & 2 deletions back/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
FROM node:20.8.0-alpine

FROM node:20.8.0-alpine as builder
# possibly for future usage
# RUN apt-get update -y
# RUN apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
WORKDIR /srv/www
COPY . .
RUN npm i
RUN npm run build-prod

FROM node:20.8.0-alpine
WORKDIR /srv/www
COPY --chown=node:node --from=builder /srv/www/build/ ./
RUN npm i --omit=dev
USER node
CMD ["npm", "start"]
7 changes: 4 additions & 3 deletions back/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc -p tsconfig.json && cp *.ttf build/",
"build-prod": "npm run build && cp package.json build/",
"start": "node build/index.js",
"build": "tsc -p tsconfig.json",
"build-prod": "npm run build && cp package*.json build/",
"start-dev": "node build/index.js",
"start": "node index.js",
"dev": "npm run build && DEBUG=1 npm run start"
},
"author": "",
Expand Down
46 changes: 46 additions & 0 deletions back/src/_tmp/otherViews.ts.tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { FastifyReply, FastifyRequest } from "fastify";
// import { open as openLmdb } from "lmdb";
// import * as config from "./config.js";

type RedirectRequest = FastifyRequest<{
Querystring: { where: string };
}>;
// type StoreRequest = FastifyRequest<{
// Querystring: { fullpath: string };
// }>;

// const lmdbHandler = openLmdb(config.READS_STORE_PATH, {});

// export async function storeReadCount(
// request: StoreRequest,
// serverReply: FastifyReply
// ) {
// if (
// !request.query.fullpath ||
// !request.query.fullpath.startsWith("/") ||
// request.query.fullpath.length < config.MIN_URL_FOR_READS_LENGTH
// ) {
// await serverReply.code(400).send("Not provided proper fullpath");
// }
// const preparedPath = request.query.fullpath
// .substring(0, config.MAX_URL_FOR_READS_LENGTH)
// .trim();
// const previousCountRaw = parseInt(await lmdbHandler.get(preparedPath), 10);
// const newCountValue = (isNaN(previousCountRaw) ? 0 : previousCountRaw) + 1;
// await lmdbHandler.put(preparedPath, newCountValue);
// serverReply.code(200).send({ count: newCountValue });
// await serverReply;
// }

export async function redirectSomewhere(
request: RedirectRequest,
serverReply: FastifyReply
) {
const preparedWhere = request.query.where.trim();
if (preparedWhere) {
serverReply.code(301).redirect(preparedWhere);
} else {
serverReply.code(400).send("Not provided place where to redirect");
}
await serverReply;
}
File renamed without changes.
28 changes: 0 additions & 28 deletions back/src/otherViews.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,8 @@
import { FastifyReply, FastifyRequest } from "fastify";
// import { open as openLmdb } from "lmdb";
// import * as config from "./config.js";

type RedirectRequest = FastifyRequest<{
Querystring: { where: string };
}>;
// type StoreRequest = FastifyRequest<{
// Querystring: { fullpath: string };
// }>;

// const lmdbHandler = openLmdb(config.READS_STORE_PATH, {});

// export async function storeReadCount(
// request: StoreRequest,
// serverReply: FastifyReply
// ) {
// if (
// !request.query.fullpath ||
// !request.query.fullpath.startsWith("/") ||
// request.query.fullpath.length < config.MIN_URL_FOR_READS_LENGTH
// ) {
// await serverReply.code(400).send("Not provided proper fullpath");
// }
// const preparedPath = request.query.fullpath
// .substring(0, config.MAX_URL_FOR_READS_LENGTH)
// .trim();
// const previousCountRaw = parseInt(await lmdbHandler.get(preparedPath), 10);
// const newCountValue = (isNaN(previousCountRaw) ? 0 : previousCountRaw) + 1;
// await lmdbHandler.put(preparedPath, newCountValue);
// serverReply.code(200).send({ count: newCountValue });
// await serverReply;
// }

export async function redirectSomewhere(
request: RedirectRequest,
Expand Down

0 comments on commit ef12e17

Please sign in to comment.