Skip to content

Instantly share code, notes, and snippets.

@nzvtrk
nzvtrk / Dockerfile
Last active April 23, 2024 06:08
Nest.js multi-stage build dockerfile + docker-compose with postgres & migrations
FROM node:12.14.1-alpine AS build
# If you have troubles with node-gyp use should install these dependencies
RUN apk add g++ make python
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . ./
# build js & remove devDependencies from node_modules
@nzvtrk
nzvtrk / memoizeDebounce.js
Last active October 6, 2022 12:58
Memoized debounce using lodash for async fetching
import { debounce } from 'lodash';
import axios from 'axios';
// or vanilla debounce
// const debounce = (func, timeOut) => {
// let timer
//
// return (...args) => {
// if (timer) clearTimeout(timer)
// timer = setTimeout(func, timeOut)
@nzvtrk
nzvtrk / nginx.conf
Last active October 13, 2019 21:03
Nginx prerender-spa config
root /usr/share/nginx/html;
# default spa conf
location / {
try_files $uri $uri/ /index.html;
}
# regexp, including page folders/paths
set $pages "faq|about|choice|gift|feedback|payment|oneplusone";
@nzvtrk
nzvtrk / axiosInterceptor.js
Last active December 7, 2023 17:21
Axios create/recreate cookie session in node.js enviroment
/* Basic example of saving cookie using axios in node.js and session's recreation after expiration.
* We have to getting/saving cookie manually because WithCredential axios param use XHR and doesn't work in node.js
* Also, this example supports parallel request and send only one create session request.
* */
const BASE_URL = "https://google.com";
// Init instance of axios which works with BASE_URL
const axiosInstance = axios.create({ baseURL: BASE_URL });