diff --git a/.env b/.env index 5ed4cab0..c7c1ddc0 100644 --- a/.env +++ b/.env @@ -34,6 +34,9 @@ RATE_LIMIT_LONG_MAX=200 ## How long to wait before the backend gives up scraping a link LINK_TIMEOUT=15 seconds +## Add the link anyway. Need for private link with auth +USE_ANY_LINK_STATUS=false + ## How long the cache should last for a redirect/301 CACHE_MAX_AGE=10 years diff --git a/Dockerfile b/Dockerfile index f7831555..4d9e5b60 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 #----------------------------------------# # dev/test -FROM node:lts-alpine AS deps +FROM node:18.17-alpine AS deps RUN apk add --no-cache --virtual .gyp python3 make g++ libc6-compat && \ npm i -g npm ENV NPM_CONFIG_PREFER_OFFLINE=true @@ -19,7 +19,7 @@ COPY --chown=node:node . . #----------------------------------------# # We have a separate build container to persist build artifacts & production npm deps -FROM node:lts-alpine AS build +FROM node:18.17-alpine AS build RUN apk add --no-cache --virtual .gyp python3 make g++ libc6-compat && \ npm i -g npm ENV NPM_CONFIG_PREFER_OFFLINE=true @@ -37,7 +37,7 @@ RUN npm run build && \ #----------------------------------------# -FROM node:lts-alpine AS runner +FROM node:18.17-alpine AS runner RUN apk add --no-cache tini USER node diff --git a/lib/scrape.js b/lib/scrape.js index da6beaaa..04961091 100644 --- a/lib/scrape.js +++ b/lib/scrape.js @@ -36,6 +36,10 @@ module.exports = async url => { }) return metascraper({ html, url: finalUrl }) } catch (err) { + if (process.env.USE_ANY_LINK_STATUS == 'true') { + requestLogger.warn(`Ignoring error for URL ${url} due to USE_ANY_LINK_STATUS:`, err.message) + return null + } if (err.name === 'RequestError' && err.code === 'ENOTFOUND') throw httpError(404, 'The address to shorten does not exist!') if (err.name === 'TimeoutError') diff --git a/models/link.js b/models/link.js index 45927f0e..3d142075 100644 --- a/models/link.js +++ b/models/link.js @@ -9,7 +9,13 @@ const { URL } = require('url') const normalizeUrl = require('normalize-url') const domain = new URL(process.env.BASE_URL).host + class Link extends hashId(BaseModel) { + + static get hashIdAlphabet() { + return 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_'; + } + static get relationMappings() { return { creator: {