mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
build: affine Node.js server charts (#2895)
This commit is contained in:
@@ -1,14 +1,28 @@
|
||||
import { Storage } from '@affine/storage';
|
||||
import { createRequire } from 'node:module';
|
||||
|
||||
import type { Storage } from '@affine/storage';
|
||||
import { type DynamicModule, type FactoryProvider } from '@nestjs/common';
|
||||
|
||||
import { Config } from '../config';
|
||||
|
||||
export const StorageProvide = Symbol('Storage');
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
export class StorageModule {
|
||||
static forRoot(): DynamicModule {
|
||||
const storageProvider: FactoryProvider = {
|
||||
provide: Storage,
|
||||
provide: StorageProvide,
|
||||
useFactory: async (config: Config) => {
|
||||
return Storage.connect(config.db.url);
|
||||
let StorageFactory: typeof Storage;
|
||||
try {
|
||||
// dev mode
|
||||
StorageFactory = (await import('@affine/storage')).Storage;
|
||||
} catch {
|
||||
// In docker
|
||||
StorageFactory = require('../../storage.node').Storage;
|
||||
}
|
||||
return StorageFactory.connect(config.db.url);
|
||||
},
|
||||
inject: [Config],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user