fix: copy FA fonts to build directory instead of serving them directly (#11891)

resolves issues when proxies don't fall back to NodeBB for assets
isekai-main
Opliko 1 year ago committed by GitHub
parent 9608b124a2
commit ac4623ee6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,4 +1,4 @@
$fa-font-path: "./vendor/fontawesome/webfonts";
$fa-font-path: "./fontawesome/webfonts";
@import "fontawesome";
@import "v4-shims";
@import "nodebb-shims";

@ -5,6 +5,7 @@ const winston = require('winston');
const nconf = require('nconf');
const fs = require('fs');
const path = require('path');
const { mkdirp } = require('mkdirp');
const plugins = require('../plugins');
const db = require('../database');
@ -139,6 +140,20 @@ function getFontawesomeStyle() {
return styles.map(style => `@import "fontawesome/style-${style}";`).join('\n');
}
async function copyFontAwesomeFiles() {
await mkdirp(path.join(__dirname, '../../build/public/fontawesome/webfonts'));
const fonts = await fs.promises.opendir(path.join(utils.getFontawesomePath(), '/webfonts'));
const copyOperations = [];
for await (const file of fonts) {
if (file.isFile() && file.name.match(/\.(woff2|ttf|eot)?$/)) { // there shouldn't be any legacy eot files, but just in case we'll allow it
copyOperations.push(
fs.promises.copyFile(path.join(fonts.path, file.name), path.join(__dirname, '../../build/public/fontawesome/webfonts/', file.name))
);
}
}
await Promise.all(copyOperations);
}
async function filterMissingFiles(filepaths) {
const exists = await Promise.all(
filepaths.map(async (filepath) => {
@ -186,7 +201,7 @@ async function getBundleMetadata(target) {
const paths = [
path.join(__dirname, '../../node_modules'),
path.join(__dirname, '../../public/scss'),
path.join(__dirname, '../../public/vendor/fontawesome/scss'),
path.join(__dirname, '../../public/fontawesome/scss'),
path.join(utils.getFontawesomePath(), 'scss'),
];
@ -324,6 +339,7 @@ CSS.buildBundle = async function (target, fork) {
await Promise.all([
fs.promises.writeFile(path.join(__dirname, '../../build/public', `${target}.css`), ltr.code),
fs.promises.writeFile(path.join(__dirname, '../../build/public', `${target}-rtl.css`), rtl.code),
copyFontAwesomeFiles(),
]);
return [ltr.code, rtl.code];
};

@ -9,7 +9,6 @@ const meta = require('../meta');
const controllers = require('../controllers');
const controllerHelpers = require('../controllers/helpers');
const plugins = require('../plugins');
const utils = require('../utils');
const authRoutes = require('./authentication');
const writeRoutes = require('./write');
@ -173,7 +172,6 @@ function addCoreRoutes(app, router, middleware, mounts) {
const statics = [
{ route: '/assets', path: path.join(__dirname, '../../build/public') },
{ route: '/assets', path: path.join(__dirname, '../../public') },
{ route: '/assets/vendor/fontawesome/webfonts', path: path.join(utils.getFontawesomePath(), 'webfonts') },
];
const staticOptions = {
maxAge: app.enabled('cache') ? 5184000000 : 0,

Loading…
Cancel
Save