Skip to content

Commit

Permalink
Add handling for custom public/images
Browse files Browse the repository at this point in the history
Support for custom public/images was recently added in official
version of Library. It does not cover development mode, though.
With these changes, custom public/images is used in development
mode. In this implementation, custom/public/images simply
overrides the public/images contents, so they cannot be combined.
  • Loading branch information
tommi-h authored and oamaok committed Nov 7, 2024
1 parent 4aeeb2c commit 9c2a2f5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
const fs = require('fs')
const path = require('path')

const express = require('express')
Expand Down Expand Up @@ -43,8 +44,17 @@ preload.forEach((middleware) => app.use(middleware))

app.use(formatUrl('/'), userInfo)

// serve all files in the public folder
app.use(formatUrl('/assets'), express.static(path.join(__dirname, '../public')))
const customImagesDir = path.join(__dirname, '../custom/public/images')
const customImagesDirExists = fs.existsSync(customImagesDir)
if (customImagesDirExists) {
// serve public/images from custom dir and other public assets from public dir
app.use('/assets/images', express.static(customImagesDir))
app.use('/assets/css', express.static(path.join(__dirname, '../public/css')))
app.use('/assets/scripts', express.static(path.join(__dirname, '../public/scripts')))
} else {
// serve all files in the public folder
app.use('/assets', express.static(path.join(__dirname, '../public')))
}

// strip trailing slashes from URLs
app.get(/(.+)\/$/, (req, res, next) => {
Expand Down

0 comments on commit 9c2a2f5

Please sign in to comment.