mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat: support self-host docker build (#5506)
Test command: `docker compose -f ./.github/deployment/self-host/compose.yaml up`
This commit is contained in:
@@ -3,7 +3,7 @@ import { APP_INTERCEPTOR } from '@nestjs/core';
|
||||
|
||||
import { AppController } from './app.controller';
|
||||
import { CacheInterceptor, CacheModule } from './cache';
|
||||
import { ConfigModule } from './config';
|
||||
import { ConfigModule, SERVER_FLAVOR } from './config';
|
||||
import { EventModule } from './event';
|
||||
import { BusinessModules } from './modules';
|
||||
import { AuthModule } from './modules/auth';
|
||||
@@ -29,6 +29,6 @@ const BasicModules = [
|
||||
},
|
||||
],
|
||||
imports: [...BasicModules, ...BusinessModules],
|
||||
controllers: [AppController],
|
||||
controllers: SERVER_FLAVOR === 'selfhosted' ? [] : [AppController],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
@@ -91,6 +91,7 @@ export interface AFFiNEConfig {
|
||||
* @env NODE_ENV
|
||||
*/
|
||||
readonly env: string;
|
||||
|
||||
/**
|
||||
* fast AFFiNE environment judge
|
||||
*/
|
||||
|
||||
@@ -49,6 +49,7 @@ const jwtKeyPair = (function () {
|
||||
})();
|
||||
|
||||
export const getDefaultAFFiNEConfig: () => AFFiNEConfig = () => {
|
||||
let isHttps: boolean | null = null;
|
||||
const defaultConfig = {
|
||||
serverId: 'affine-nestjs-server',
|
||||
version: pkg.version,
|
||||
@@ -56,6 +57,7 @@ export const getDefaultAFFiNEConfig: () => AFFiNEConfig = () => {
|
||||
AFFINE_SERVER_PORT: ['port', 'int'],
|
||||
AFFINE_SERVER_HOST: 'host',
|
||||
AFFINE_SERVER_SUB_PATH: 'path',
|
||||
AFFIHE_SERVER_HTTPS: 'https',
|
||||
AFFINE_ENV: 'affineEnv',
|
||||
DATABASE_URL: 'db.url',
|
||||
ENABLE_CAPTCHA: ['auth.captcha.enable', 'boolean'],
|
||||
@@ -117,7 +119,10 @@ export const getDefaultAFFiNEConfig: () => AFFiNEConfig = () => {
|
||||
earlyAccessPreview: false,
|
||||
},
|
||||
get https() {
|
||||
return !this.node.dev;
|
||||
return isHttps ?? !this.node.dev;
|
||||
},
|
||||
set https(value: boolean) {
|
||||
isHttps = value;
|
||||
},
|
||||
host: 'localhost',
|
||||
port: 3010,
|
||||
|
||||
@@ -33,6 +33,7 @@ import prismaInstrument from '@prisma/instrumentation';
|
||||
|
||||
const { PrismaInstrumentation } = prismaInstrument;
|
||||
|
||||
import { parseEnvValue } from '../config/def';
|
||||
import { PrismaMetricProducer } from './prisma';
|
||||
|
||||
abstract class OpentelemetryFactor {
|
||||
@@ -155,6 +156,9 @@ export function getMeter(name = 'business') {
|
||||
}
|
||||
|
||||
export function start() {
|
||||
if (parseEnvValue(process.env.DISABLE_TELEMETRY, 'boolean')) {
|
||||
return;
|
||||
}
|
||||
const sdk = createSDK();
|
||||
|
||||
if (sdk) {
|
||||
|
||||
@@ -179,7 +179,7 @@ export const NextAuthOptionsProvider: FactoryProvider<NextAuthOptions> = {
|
||||
);
|
||||
}
|
||||
|
||||
if (config.auth.oauthProviders.google) {
|
||||
if (config.auth.oauthProviders.google?.enabled) {
|
||||
nextAuthOptions.providers.push(
|
||||
// @ts-expect-error esm interop issue
|
||||
Google.default({
|
||||
|
||||
@@ -186,15 +186,17 @@ export class NextAuthController {
|
||||
}
|
||||
|
||||
let nextAuthTokenCookie: (CookieOption & { value: string }) | undefined;
|
||||
const cookiePrefix = this.config.node.prod ? '__Secure-' : '';
|
||||
const sessionCookieName = `${cookiePrefix}next-auth.session-token`;
|
||||
const secureCookiePrefix = '__Secure-';
|
||||
const sessionCookieName = `next-auth.session-token`;
|
||||
// next-auth credentials login only support JWT strategy
|
||||
// https://next-auth.js.org/configuration/providers/credentials
|
||||
// let's store the session token in the database
|
||||
if (
|
||||
credentialsSignIn &&
|
||||
(nextAuthTokenCookie = cookies?.find(
|
||||
({ name }) => name === sessionCookieName
|
||||
({ name }) =>
|
||||
name === sessionCookieName ||
|
||||
name === `${secureCookiePrefix}${sessionCookieName}`
|
||||
))
|
||||
) {
|
||||
const cookieExpires = new Date();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { join } from 'node:path';
|
||||
|
||||
import { DynamicModule, Type } from '@nestjs/common';
|
||||
import { ScheduleModule } from '@nestjs/schedule';
|
||||
import { ServeStaticModule } from '@nestjs/serve-static';
|
||||
|
||||
import { SERVER_FLAVOR } from '../config';
|
||||
import { GqlModule } from '../graphql.module';
|
||||
@@ -29,7 +32,10 @@ switch (SERVER_FLAVOR) {
|
||||
UsersModule,
|
||||
SyncModule,
|
||||
DocModule,
|
||||
StorageModule
|
||||
StorageModule,
|
||||
ServeStaticModule.forRoot({
|
||||
rootPath: join('/app', 'static'),
|
||||
})
|
||||
);
|
||||
break;
|
||||
case 'graphql':
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
import { homedir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
|
||||
import { config } from 'dotenv';
|
||||
|
||||
import { SERVER_FLAVOR } from './config/default';
|
||||
|
||||
if (SERVER_FLAVOR === 'selfhosted') {
|
||||
config({ path: join(homedir(), '.affine', '.env') });
|
||||
} else {
|
||||
config();
|
||||
}
|
||||
|
||||
import 'reflect-metadata';
|
||||
import 'dotenv/config';
|
||||
import './affine';
|
||||
import './affine.config';
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@ try {
|
||||
storageModule =
|
||||
process.arch === 'arm64'
|
||||
? require('../../storage.arm64.node')
|
||||
: require('../../storage.node');
|
||||
: process.arch === 'arm'
|
||||
? require('../../storage.armv7.node')
|
||||
: require('../../storage.node');
|
||||
}
|
||||
|
||||
export { storageModule as OctoBaseStorageModule };
|
||||
|
||||
Reference in New Issue
Block a user