@plone/volto 14.0.0-alpha.5 → 14.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/server.jsx +53 -53
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/server.jsx
CHANGED
|
@@ -52,6 +52,10 @@ if (config.settings) {
|
|
|
52
52
|
|
|
53
53
|
const supported = new locale.Locales(keys(languages), 'en');
|
|
54
54
|
|
|
55
|
+
const expressMiddleware = (config.settings.expressMiddleware || []).filter(
|
|
56
|
+
(m) => typeof m !== 'undefined',
|
|
57
|
+
);
|
|
58
|
+
|
|
55
59
|
const server = express()
|
|
56
60
|
.disable('x-powered-by')
|
|
57
61
|
.use(express.static(process.env.RAZZLE_PUBLIC_DIR))
|
|
@@ -60,6 +64,55 @@ const server = express()
|
|
|
60
64
|
res.send('');
|
|
61
65
|
});
|
|
62
66
|
|
|
67
|
+
if (expressMiddleware.length) server.use('/', expressMiddleware);
|
|
68
|
+
|
|
69
|
+
// Internal proxy to bypass CORS while developing.
|
|
70
|
+
if (__DEVELOPMENT__ && config.settings.devProxyToApiPath) {
|
|
71
|
+
// This is the proxy to the API in case the accept header is 'application/json'
|
|
72
|
+
const filter = function (pathname, req) {
|
|
73
|
+
return req.headers.accept === 'application/json';
|
|
74
|
+
};
|
|
75
|
+
const apiPathURL = parseUrl(config.settings.apiPath);
|
|
76
|
+
const proxyURL = parseUrl(config.settings.devProxyToApiPath);
|
|
77
|
+
const serverURL = `${proxyURL.protocol}//${proxyURL.host}`;
|
|
78
|
+
const instancePath = proxyURL.pathname;
|
|
79
|
+
|
|
80
|
+
const proxyMiddleware = createProxyMiddleware(filter, {
|
|
81
|
+
onProxyReq: (proxyReq, req, res) => {
|
|
82
|
+
// Fixes https://github.com/chimurai/http-proxy-middleware/issues/320
|
|
83
|
+
if (!req.body || !Object.keys(req.body).length) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const contentType = proxyReq.getHeader('Content-Type');
|
|
88
|
+
const writeBody = (bodyData) => {
|
|
89
|
+
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
|
|
90
|
+
proxyReq.write(bodyData);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (contentType.includes('application/json')) {
|
|
94
|
+
writeBody(JSON.stringify(req.body));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (contentType.includes('application/x-www-form-urlencoded')) {
|
|
98
|
+
writeBody(querystring.stringify(req.body));
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
target: serverURL,
|
|
102
|
+
pathRewrite: {
|
|
103
|
+
'^/':
|
|
104
|
+
config.settings.proxyRewriteTarget ||
|
|
105
|
+
`/VirtualHostBase/http/${apiPathURL.hostname}:${apiPathURL.port}${instancePath}/VirtualHostRoot/`,
|
|
106
|
+
},
|
|
107
|
+
logLevel: 'silent', // change to 'debug' to see all requests
|
|
108
|
+
...(config.settings?.proxyRewriteTarget?.startsWith('https') && {
|
|
109
|
+
changeOrigin: true,
|
|
110
|
+
secure: false,
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
server.use(proxyMiddleware);
|
|
114
|
+
}
|
|
115
|
+
|
|
63
116
|
server.all('*', setupServer);
|
|
64
117
|
|
|
65
118
|
function setupServer(req, res, next) {
|
|
@@ -133,59 +186,6 @@ function setupServer(req, res, next) {
|
|
|
133
186
|
next();
|
|
134
187
|
}
|
|
135
188
|
|
|
136
|
-
const expressMiddleware = (config.settings.expressMiddleware || []).filter(
|
|
137
|
-
(m) => typeof m !== 'undefined',
|
|
138
|
-
);
|
|
139
|
-
if (expressMiddleware.length) server.use('/', expressMiddleware);
|
|
140
|
-
|
|
141
|
-
// Internal proxy to bypass CORS while developing.
|
|
142
|
-
if (__DEVELOPMENT__ && config.settings.devProxyToApiPath) {
|
|
143
|
-
// This is the proxy to the API in case the accept header is 'application/json'
|
|
144
|
-
const filter = function (pathname, req) {
|
|
145
|
-
return req.headers.accept === 'application/json';
|
|
146
|
-
};
|
|
147
|
-
const apiPathURL = parseUrl(config.settings.apiPath);
|
|
148
|
-
const proxyURL = parseUrl(config.settings.devProxyToApiPath);
|
|
149
|
-
const serverURL = `${proxyURL.protocol}//${proxyURL.host}`;
|
|
150
|
-
const instancePath = proxyURL.pathname;
|
|
151
|
-
|
|
152
|
-
const proxyMiddleware = createProxyMiddleware(filter, {
|
|
153
|
-
onProxyReq: (proxyReq, req, res) => {
|
|
154
|
-
// Fixes https://github.com/chimurai/http-proxy-middleware/issues/320
|
|
155
|
-
if (!req.body || !Object.keys(req.body).length) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const contentType = proxyReq.getHeader('Content-Type');
|
|
160
|
-
const writeBody = (bodyData) => {
|
|
161
|
-
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
|
|
162
|
-
proxyReq.write(bodyData);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
if (contentType.includes('application/json')) {
|
|
166
|
-
writeBody(JSON.stringify(req.body));
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (contentType.includes('application/x-www-form-urlencoded')) {
|
|
170
|
-
writeBody(querystring.stringify(req.body));
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
target: serverURL,
|
|
174
|
-
pathRewrite: {
|
|
175
|
-
'^/':
|
|
176
|
-
config.settings.proxyRewriteTarget ||
|
|
177
|
-
`/VirtualHostBase/http/${apiPathURL.hostname}:${apiPathURL.port}${instancePath}/VirtualHostRoot/`,
|
|
178
|
-
},
|
|
179
|
-
logLevel: 'silent', // change to 'debug' to see all requests
|
|
180
|
-
...(config.settings?.proxyRewriteTarget?.startsWith('https') && {
|
|
181
|
-
changeOrigin: true,
|
|
182
|
-
secure: false,
|
|
183
|
-
}),
|
|
184
|
-
});
|
|
185
|
-
// server.use(express.json());
|
|
186
|
-
server.use(proxyMiddleware);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
189
|
server.get('/*', (req, res) => {
|
|
190
190
|
const { store, api, errorHandler } = req.app.locals;
|
|
191
191
|
|