Skip to content

Commit

Permalink
Settle on the config for now of the middlewares and the proxy and get…
Browse files Browse the repository at this point in the history
… along with the weird chunk not found
  • Loading branch information
sneridagh committed Sep 20, 2024
1 parent 02caa23 commit 54c32d7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
6 changes: 4 additions & 2 deletions packages/volto/src/config/server.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// import imagesMiddleware from '@plone/volto/express-middleware/images';
// import filesMiddleware from '@plone/volto/express-middleware/files';
// import robotstxtMiddleware from '@plone/volto/express-middleware/robotstxt';
// import okMiddleware from '@plone/volto/express-middleware/ok';
import okMiddleware from '@plone/volto/express-middleware/ok';
// import sitemapMiddleware from '@plone/volto/express-middleware/sitemap';
// import staticsMiddleware from '@plone/volto/express-middleware/static';
import devProxyMiddleware from '../express-middleware/devproxy';
import hostDetectionFn from '../express-middleware/hostDetect';

const settings = {
expressMiddleware: [
hostDetectionFn(),
devProxyMiddleware(),
// filesMiddleware(),
// imagesMiddleware(),
// robotstxtMiddleware(),
// okMiddleware(),
okMiddleware(),
// sitemapMiddleware(),
// staticsMiddleware(),
],
Expand Down
24 changes: 24 additions & 0 deletions packages/volto/src/express-middleware/hostDetect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import express from 'express';
import config from '@plone/volto/registry';

function hostDetectionFn(req, res, next) {
res.locals.apiPath = config.settings.apiPath;
res.locals.devProxyToApiPath = config.settings.devProxyToApiPath;
res.locals.proxyRewriteTarget = config.settings.proxyRewriteTarget;

if (!process.env.VITE_API_PATH && req.headers.host) {
res.locals.detectedHost = `${
req.headers['x-forwarded-proto'] || req.protocol
}://${req.headers.host}`;
}

next();
}

export default function hostDetectionMiddleware() {
const middleware = express.Router();

middleware.all(['*'], hostDetectionFn);
middleware.id = 'hostDetection';
return middleware;
}
16 changes: 0 additions & 16 deletions packages/volto/src/vite-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,6 @@ export async function createServer(
const currentConfig = (await vite.ssrLoadModule('/src/config')).currentConfig;
// console.log(currentConfig);

// This is the loader of the former "Seamless" mode parameters from the headers
app.all('*', async function loadVoltoConfig(req, res, next) {
// const config = await vite.ssrLoadModule('/src/config');
res.locals.apiPath = currentConfig.settings.apiPath;
res.locals.devProxyToApiPath = currentConfig.settings.devProxyToApiPath;
res.locals.proxyRewriteTarget = currentConfig.settings.proxyRewriteTarget;

if (!process.env.VITE_API_PATH && req.headers.host) {
res.locals.detectedHost = `${
req.headers['x-forwarded-proto'] || req.protocol
}://${req.headers.host}`;
}

next();
});

// Loads the Express server middleware from the settings.
const middleware = (
currentConfig.settings.serverConfig.expressMiddleware || []
Expand Down
14 changes: 7 additions & 7 deletions packages/volto/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export default defineConfig({
}),
react(),
],
// server: {
// port: 3000,
// proxy: {
// '/++api++/':
// 'http://localhost:8080/VirtualHostBase/http/localhost:3000/Plone/++api++/VirtualHostRoot',
// },
// },
server: {
port: 3000,
proxy: {
'/++api++/':
'http://localhost:8080/VirtualHostBase/http/localhost:3000/Plone/++api++/VirtualHostRoot',
},
},
resolve: {
alias: [
{ find: /^~/, replacement: '' },
Expand Down

0 comments on commit 54c32d7

Please sign in to comment.