Start using req.resources = { app, volume, ...} pattern
Reason was that req.app was clashing with expressjs v5 which stores the main expressjs app object there
This commit is contained in:
@@ -25,7 +25,7 @@ let gHttpServer = null;
|
||||
async function authorizeApp(req, res, next) {
|
||||
// make the tests pass for now
|
||||
if (constants.TEST) {
|
||||
req.app = { id: 'testappid' };
|
||||
req.resources.app = { id: 'testappid' };
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ async function authorizeApp(req, res, next) {
|
||||
if (!app) return next(new HttpError(401, 'Unauthorized'));
|
||||
if (!app.manifest.addons?.docker) return next(new HttpError(401, 'Unauthorized'));
|
||||
|
||||
req.app = app;
|
||||
req.resources.app = app;
|
||||
|
||||
next();
|
||||
}
|
||||
@@ -65,10 +65,10 @@ function attachDockerRequest(req, res, next) {
|
||||
async function containersCreate(req, res, next) {
|
||||
safe.set(req.body, 'HostConfig.NetworkMode', 'cloudron'); // overwrite the network the container lives in
|
||||
safe.set(req.body, 'NetworkingConfig', {}); // drop any custom network configs
|
||||
safe.set(req.body, 'Labels', Object.assign({}, safe.query(req.body, 'Labels'), { appId: req.app.id, isCloudronManaged: String(false) })); // overwrite the app id to track containers of an app
|
||||
safe.set(req.body, 'HostConfig.LogConfig', { Type: 'syslog', Config: { 'tag': req.app.id, 'syslog-address': `unix://${paths.SYSLOG_SOCKET_FILE}`, 'syslog-format': 'rfc5424' }});
|
||||
safe.set(req.body, 'Labels', Object.assign({}, safe.query(req.body, 'Labels'), { appId: req.resources.app.id, isCloudronManaged: String(false) })); // overwrite the app id to track containers of an app
|
||||
safe.set(req.body, 'HostConfig.LogConfig', { Type: 'syslog', Config: { 'tag': req.resources.app.id, 'syslog-address': `unix://${paths.SYSLOG_SOCKET_FILE}`, 'syslog-format': 'rfc5424' }});
|
||||
|
||||
const appDataDir = path.join(paths.APPS_DATA_DIR, req.app.id, 'data');
|
||||
const appDataDir = path.join(paths.APPS_DATA_DIR, req.resources.app.id, 'data');
|
||||
|
||||
debug('containersCreate: original bind mounts:', req.body.HostConfig.Binds);
|
||||
|
||||
@@ -137,6 +137,11 @@ async function start() {
|
||||
proxyServer.use(authorizeApp)
|
||||
.use(attachDockerRequest)
|
||||
.use(json)
|
||||
.use((req, res , next) => {
|
||||
// we store our route resources, like app,volumes,... in req.resources. Those are added in the load() routes
|
||||
req.resources = {};
|
||||
next();
|
||||
})
|
||||
.use(router)
|
||||
.use(process)
|
||||
.use(middleware.lastMile());
|
||||
|
||||
Reference in New Issue
Block a user