Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function boot(port: number, addr: string) {
// Tell routing-controller to use our dependency injection container
useContainer(Container);
// Wires all dependencies
const vaultPath = storagePath(VAULT_FILENAME, program.data);
Container.set('cipherLocation', vaultPath);
await loadConfig(true);
Container.set(DatabaseWithAuth, Container.get(JSONDatabaseWithAuth));
// Create an express server which is preconfigured to serve the API
const server = createVaultageAPIServer();
// Bind static content to server
const pathToWebCliGUI = path.dirname(require.resolve('vaultage-ui-webcli'));
const staticDirToServer = path.join(pathToWebCliGUI, 'public');
server.use(express.static(staticDirToServer));
// run application on port port
server.listen(port, addr, () => {
console.log(`Server is listening on port ${port}`);
async function boot(port: number, addr: string) {
// Tell routing-controller to use our dependency injection container
useContainer(Container);
// Wires all dependencies
const vaultPath = storagePath(VAULT_FILENAME, program.data);
Container.set('cipherLocation', vaultPath);
await loadConfig(true);
Container.set(DatabaseWithAuth, Container.get(JSONDatabaseWithAuth));
// Create an express server which is preconfigured to serve the API
const server = createVaultageAPIServer();
// Bind static content to server
const pathToWebCliGUI = path.dirname(require.resolve('vaultage-ui-webcli'));
const staticDirToServer = path.join(pathToWebCliGUI, 'public');
server.use(express.static(staticDirToServer));
// run application on port port
server.listen(port, addr, () => {
console.log(`Server is listening on port ${port}`);
});
}
export function setSamplesInContainer() {
// add sample recipes to container
Container.set({
id: "SAMPLE_RECIPES",
transient: true, // create a fresh copy for each `get` of samples
factory: () => {
console.log("sampleRecipes copy created!");
return sampleRecipes.slice();
},
});
}
willSendResponse(requestContext: GraphQLRequestContext) {
// remember to dispose the scoped container to prevent memory leaks
Container.reset(requestContext.context.requestId);
// for developers curiosity purpose, here is the logging of current scoped container instances
// we can make multiple parallel requests to see in console how this works
const instancesIds = ((Container as any).instances as ContainerInstance[]).map(
instance => instance.id,
);
console.log("instances left in memory:", instancesIds);
},
}),
constructor() {
this.log = Container.get(Logger).for(this);
const appConfig = Container.get>(AppConfig);
this.dev = appConfig.env === ENV_DEV;
this.options = appConfig.static;
// warmup lib
for (const [key, fn] of Object.entries(this.options)) {
this._paths.push(key);
const raw = this.content[key] = readSync(fn);
const size = Math.round(raw.length / 1024)
this.log.info(`Loaded static file: ${key}/${fn} ${size}kb`)
}
}
constructor() {
this.log = Container.get(Logger).for(this);
const appConfig = Container.get>(AppConfig);
this.dev = appConfig.env === ENV_DEV;
this.options = appConfig.static;
// warmup lib
for (const [key, fn] of Object.entries(this.options)) {
this._paths.push(key);
const raw = this.content[key] = readSync(fn);
const size = Math.round(raw.length / 1024)
this.log.info(`Loaded static file: ${key}/${fn} ${size}kb`)
}
}
}
const defaultProfile: Profile = {
// 是否启用host解析
enableHost: true,
// 是否启用转发规则
enableRule: true,
// 工程路径配置
projectPath: {},
};
/**
* 代理运转需要的规则数据
* 代理端口、超时时间、gitlab token、工程路径、是否启用转发规则
* Created by tsxuehu on 8/3/17.
*/
@Service()
export class ProfileService extends EventEmitter {
private userProfileMap: object;
private clientIpUserMap: object;
private profileSaveDir: string;
private clientIpUserMapSaveFile: string;
constructor(appInfoService: AppInfoService) {
super();
// userId -> profile
this.userProfileMap = {};
// clientIp -> userId
this.clientIpUserMap = {};
const proxyDataDir = appInfoService.getProxyDataDir();
this.profileSaveDir = path.join(proxyDataDir, 'profile');
this.clientIpUserMapSaveFile = path.join(proxyDataDir, 'clientIpUserMap.json');
public static bindToServer(expressApp: Application, initialConfig?: VaultageConfig ) {
if (initialConfig) {
Container.set('config', initialConfig);
}
// registers our routes (present in Cipher/ConfigController) on this express server
useExpressServer(expressApp, {
controllers: [
CipherController,
ConfigController
]
});
}
}
constructor(@Inject('SegmentService') readonly service: SegmentService) {
// no-empty
}
constructor(@Inject('FeatureFlagSegmentService') readonly service: FeatureFlagSegmentService) {
// no-empty
}