Initial commit
This commit is contained in:
47
api/config/index.ts
Normal file
47
api/config/index.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import os from 'os'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
|
||||
export const config = {
|
||||
get projectRoot(): string {
|
||||
if (__dirname.includes('app.asar')) {
|
||||
return path.resolve(__dirname, '..').replace('app.asar', 'app.asar.unpacked')
|
||||
}
|
||||
return path.resolve(__dirname, '../../')
|
||||
},
|
||||
|
||||
get notebookRoot(): string {
|
||||
return process.env.NOTEBOOK_ROOT
|
||||
? path.resolve(process.env.NOTEBOOK_ROOT)
|
||||
: path.join(this.projectRoot, 'notebook')
|
||||
},
|
||||
|
||||
get tempRoot(): string {
|
||||
return path.join(os.tmpdir(), 'xcnote_uploads')
|
||||
},
|
||||
|
||||
get serverPort(): number {
|
||||
return parseInt(process.env.PORT || '3001', 10)
|
||||
},
|
||||
|
||||
get isVercel(): boolean {
|
||||
return !!process.env.VERCEL
|
||||
},
|
||||
|
||||
get isElectron(): boolean {
|
||||
return __dirname.includes('app.asar')
|
||||
},
|
||||
|
||||
get isDev(): boolean {
|
||||
return !this.isElectron && !this.isVercel
|
||||
},
|
||||
}
|
||||
|
||||
export const PATHS = {
|
||||
get PROJECT_ROOT() { return config.projectRoot },
|
||||
get NOTEBOOK_ROOT() { return config.notebookRoot },
|
||||
get TEMP_ROOT() { return config.tempRoot },
|
||||
}
|
||||
7
api/config/paths.ts
Normal file
7
api/config/paths.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { PATHS, config } from './index.js'
|
||||
|
||||
export { PATHS, config }
|
||||
|
||||
export const PROJECT_ROOT = PATHS.PROJECT_ROOT
|
||||
export const NOTEBOOK_ROOT = PATHS.NOTEBOOK_ROOT
|
||||
export const TEMP_ROOT = PATHS.TEMP_ROOT
|
||||
Reference in New Issue
Block a user