I am deploying my app in Netlify and I am facing a problem. My Nodejs, Express file does not serve the images and the fonts. The HTML, CSS and JavaScript are working.
require('dotenv').config();
const express = require('express');
const serverless = require('serverless-http');
const path = require('path');
const app = express();
const router = express.Router();
const cors = require('cors');
app.use(cors());
app.use(express.json());
router.get('/products.json', (req, res) => {
res.sendFile(path.join(__dirname, '/public/products.json'));
});
router.get('/products.json', (req, res) => {
res.sendFile(path.join(__dirname, '/public/products.json'));
});
router.use(express.static(path.join(__dirname, '../public/styles/fonts')));
router.use(express.static(path.join(__dirname, '../public/images')));
router.use(express.static(path.join(__dirname, '../public'), {
setHeaders: (res, filePath) => {
const ext = path.extname(filePath);
const mimeTypes = {
'.html': 'text/html',
'.js': 'application/javascript',
'.css': 'text/css',
};
const contentType = mimeTypes[ext];
if (contentType) {
res.setHeader('Content-Type', contentType);
}
}
}));
router.use(express.static(path.join(__dirname, '../public/styles/fonts'), {
setHeaders: (res, filePath) => {
const ext = path.extname(filePath);
const mimeTypes = {
'.ttf': 'application/font-ttf',
'.otf': 'application/font-otf',
'.eot': 'application/vnd.ms-fontobject',
'.woff': 'application/font-woff',
'.woff2': 'application/font-woff2',
'.svg': 'image/svg+xml',
};
const contentType = mimeTypes[ext];
if (contentType) {
res.setHeader('Content-Type', contentType);
}
}
}));
router.get("", (req, res) => {
res.sendFile(path.join(__dirname, '../public/views', 'index.html'));
});
app.use('/', router);
module.exports.handler = serverless(app);
and this is my netlify.toml file
[build]
functions="functions"
[[redirects]]
to="/.netlify/functions/api/:splat"
from="/*"
status=200
There are the errors that are popping in the console
Failed to decode downloaded font: http://localhost:8888/styles/fonts/Norms/NormsProMedium.ttf
localhost/:1 OTS parsing error: DSIG: misaligned table
localhost/:1 Failed to decode downloaded font: http://localhost:8888/styles/fonts/Norms/NormsProNormal.ttf
localhost/:1 OTS parsing error: DSIG: misaligned table
localhost/:1 Failed to decode downloaded font: http://localhost:8888/styles/fonts/Norms/NormsProNormal.ttf
localhost/:1 OTS parsing error: DSIG: misaligned table
localhost/:1 Failed to decode downloaded font: http://localhost:8888/styles/fonts/Norms/NormsProLight.ttf
localhost/:1 OTS parsing error: DSIG: misaligned table
localhost/:1 Failed to decode downloaded font: http://localhost:8888/styles/fonts/Norms/NormsProLight.ttf
localhost/:1 OTS parsing error: DSIG: misaligned table
Pcelarnik Danevi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.