const express = require('express'); const app = express(); const path = require('path'); const PORT = process.env.PORT || 3000; const fs = require("fs"); const { default: axios } = require('axios'); const { btoa } = require('buffer'); //const indexPath = path.resolve(__dirname, '..', 'build', 'index.html'); const indexPath = path.resolve(process.env.ROOT_PATH, 'index.html'); const iconPath = path.resolve(process.env.ROOT_PATH, 'favicon.ico'); const staticPath = path.resolve(process.env.ROOT_PATH, "static"); app.enable('trust proxy'); // static resources should just be served as they are app.use("/static", express.static( staticPath, { maxAge: '30d' }, )); const fetchMetaTags = async (url) => { const encoded = btoa(url); const resp = await axios.get(`${process.env.API_URL}meta?path=${encoded}`); console.log(resp.data) return resp.data; } const fillMetaTags = async (request, htmlData) => { const url = request.originalUrl; let title = process.env.DEFAULT_TITLE; let description = process.env.DEFAULT_DESCRIPTION; let image = ""; let icon = "/favicon.ico" try { const resp = await fetchMetaTags(url); title = resp.title ? resp.title : title; description = resp.description ? resp.description : description; image = resp.image ? resp.image : image; icon = resp.icon ? resp.icon : icon; } catch (e) { console.error(e.message) console.log("ERROR FETCHING TAGS"); } htmlData = htmlData.replace( "