mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 05:37:53 +00:00
Use v2 router directly instead of through application manager
Signed-off-by: Christina Ying Wang <christina@balena.io>
This commit is contained in:
parent
ce5bf89dfc
commit
71b2aea0fe
@ -1,4 +1,3 @@
|
||||
import * as express from 'express';
|
||||
import * as _ from 'lodash';
|
||||
import { EventEmitter } from 'events';
|
||||
import StrictEventEmitter from 'strict-event-emitter-types';
|
||||
@ -7,7 +6,7 @@ import * as config from '../config';
|
||||
import { transaction, Transaction } from '../db';
|
||||
import * as logger from '../logger';
|
||||
import LocalModeManager from '../local-mode';
|
||||
import { Proxyvisor } from '../proxyvisor';
|
||||
import proxyvisor from '../proxyvisor';
|
||||
|
||||
import * as dbFormat from '../device-state/db-format';
|
||||
import { validateTargetContracts } from '../lib/contracts';
|
||||
@ -20,7 +19,6 @@ import {
|
||||
} from '../lib/errors';
|
||||
import { lock } from '../lib/update-lock';
|
||||
import { checkTruthy } from '../lib/validation';
|
||||
import { createV2Api } from '../device-api/v2';
|
||||
|
||||
import App from './app';
|
||||
import * as volumeManager from './volume-manager';
|
||||
@ -55,19 +53,8 @@ export const removeListener: typeof events['removeListener'] =
|
||||
export const removeAllListeners: typeof events['removeAllListeners'] =
|
||||
events.removeAllListeners.bind(events);
|
||||
|
||||
const proxyvisor = new Proxyvisor();
|
||||
const localModeManager = new LocalModeManager();
|
||||
|
||||
export const router = (() => {
|
||||
const $router = express.Router();
|
||||
|
||||
createV2Api($router);
|
||||
|
||||
$router.use(proxyvisor.router);
|
||||
|
||||
return $router;
|
||||
})();
|
||||
|
||||
export let fetchesInProgress = 0;
|
||||
export let timeSpentFetching = 0;
|
||||
|
||||
|
@ -5,6 +5,7 @@ import * as middleware from './middleware';
|
||||
import * as apiKeys from './api-keys';
|
||||
import * as eventTracker from '../event-tracker';
|
||||
import * as deviceState from '../device-state';
|
||||
import proxyvisor from '../proxyvisor';
|
||||
import blink = require('../lib/blink');
|
||||
import log from '../lib/supervisor-console';
|
||||
|
||||
@ -92,6 +93,8 @@ export class SupervisorAPI {
|
||||
this.api.use(router);
|
||||
}
|
||||
|
||||
this.api.use(proxyvisor.router);
|
||||
|
||||
this.api.use(middleware.errors);
|
||||
}
|
||||
|
||||
|
@ -352,5 +352,3 @@ router.get('/v1/device', async (_req, res) => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
router.use(applicationManager.router);
|
||||
|
1003
src/device-api/v2.ts
1003
src/device-api/v2.ts
File diff suppressed because it is too large
Load Diff
@ -87,7 +87,7 @@ const formatCurrentAsState = (device) => ({
|
||||
config: device.config,
|
||||
});
|
||||
|
||||
const createProxyvisorRouter = function (proxyvisor) {
|
||||
const createProxyvisorRouter = function (pv) {
|
||||
const router = express.Router();
|
||||
router.get('/v1/devices', async (_req, res) => {
|
||||
try {
|
||||
@ -313,7 +313,7 @@ const createProxyvisorRouter = function (proxyvisor) {
|
||||
await fs.lstat(dest);
|
||||
} catch {
|
||||
await Promise.using(
|
||||
proxyvisor.docker.imageRootDirMounted(app.image),
|
||||
pv.docker.imageRootDirMounted(app.image),
|
||||
(rootDir) => getTarArchive(rootDir + '/assets', dest),
|
||||
);
|
||||
}
|
||||
@ -344,7 +344,7 @@ const createProxyvisorRouter = function (proxyvisor) {
|
||||
return router;
|
||||
};
|
||||
|
||||
export class Proxyvisor {
|
||||
class Proxyvisor {
|
||||
constructor() {
|
||||
this.executeStepAction = this.executeStepAction.bind(this);
|
||||
this.getCurrentStates = this.getCurrentStates.bind(this);
|
||||
@ -1001,3 +1001,6 @@ export class Proxyvisor {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const proxyvisor = new Proxyvisor();
|
||||
export default proxyvisor;
|
||||
|
@ -5,6 +5,7 @@ import * as deviceState from './device-state';
|
||||
import * as logger from './logger';
|
||||
import SupervisorAPI from './device-api';
|
||||
import * as v1 from './device-api/v1';
|
||||
import * as v2 from './device-api/v2';
|
||||
import logMonitor from './logging/monitor';
|
||||
|
||||
import { intialiseContractRequirements } from './lib/contracts';
|
||||
@ -67,7 +68,7 @@ export class Supervisor {
|
||||
(() => {
|
||||
log.info('Starting API server');
|
||||
this.api = new SupervisorAPI({
|
||||
routers: [v1.router],
|
||||
routers: [v1.router, v2.router],
|
||||
healthchecks: [apiBinder.healthcheck, deviceState.healthcheck],
|
||||
});
|
||||
this.api.listen(conf.listenPort, conf.apiTimeout);
|
||||
|
@ -8,6 +8,7 @@ import * as commitStore from '~/src/compose/commit';
|
||||
import * as config from '~/src/config';
|
||||
import * as db from '~/src/db';
|
||||
import * as v1 from '~/src/device-api/v1';
|
||||
import * as v2 from '~/src/device-api/v2';
|
||||
import * as deviceState from '~/src/device-state';
|
||||
import SupervisorAPI from '~/src/device-api';
|
||||
import { Service } from '~/src/compose/service';
|
||||
@ -132,7 +133,7 @@ async function create(
|
||||
|
||||
// Create SupervisorAPI
|
||||
const api = new SupervisorAPI({
|
||||
routers: [v1.router],
|
||||
routers: [v1.router, v2.router],
|
||||
healthchecks,
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user