Files
LingChair/server/config.ts
CrescentLeaf 25320fe521 refactor: 推翻舊架構, 進入 Vite 盛世!
* 所有的 CDN 依賴已全部 npm 化
* Webpack? 一邊去! Vite 太好用啦!
* 將 Imports.ts 剔除
* 移除了大量的靜態文件
* 將 index.html 的部分代碼分離
* 修改 deno task
* 移除了動態編譯頁面的支持
* ./static 引用全部變更為 npm 包引用
2025-09-07 12:49:09 +08:00

44 lines
1.2 KiB
TypeScript

import fs from 'node:fs/promises'
import chalk from 'chalk'
import { cwd } from "node:process"
const isCompilingClient = /client(\\|\/)?$/.test(cwd())
const prefix = isCompilingClient ? '.' : ''
const default_data_path = "./thewhitesilk_data"
let config = {
data_path: default_data_path,
server: {
use: "http",
/**
* used in server.listen()
*/
listen: {
port: 3601,
host: "::",
/**
* setting ipv6Only to true will disable dual-stack support, i.e., binding to host :: won't make 0.0.0.0 be bound.
*/
ipv6Only: false,
},
/**
* used in https.createServer()
*/
https: {
key: default_data_path + '/key.pem',
cert: default_data_path + '/cert.pem',
},
},
}
try {
config = JSON.parse(await fs.readFile(prefix + './thewhitesilk_config.json', 'utf-8'))
} catch (_e) {
console.log(chalk.yellow("配置文件貌似不存在, 正在创建..."))
await fs.writeFile(prefix + './thewhitesilk_config.json', JSON.stringify(config))
}
await fs.mkdir(prefix + config.data_path, { recursive: true })
export default config