* 所有的 CDN 依賴已全部 npm 化 * Webpack? 一邊去! Vite 太好用啦! * 將 Imports.ts 剔除 * 移除了大量的靜態文件 * 將 index.html 的部分代碼分離 * 修改 deno task * 移除了動態編譯頁面的支持 * ./static 引用全部變更為 npm 包引用
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import ApiManager from "./api/ApiManager.ts"
|
|
// @ts-types="npm:@types/express"
|
|
import express from 'express'
|
|
import * as SocketIo from 'socket.io'
|
|
import HttpServerLike from "./typedef/HttpServerLike.ts"
|
|
import config from './config.ts'
|
|
import http from 'node:http'
|
|
import https from 'node:https'
|
|
import readline from 'node:readline'
|
|
import process from "node:process"
|
|
import chalk from "chalk"
|
|
|
|
const app = express()
|
|
app.use((req, res, next) => {
|
|
const url = req.originalUrl || req.url
|
|
if (/\.m?(j|t)sx?$/.test(url))
|
|
res.setHeader('Content-Type', 'application/javascript')
|
|
next()
|
|
})
|
|
app.use('/', express.static(config.data_path + '/page_compiled'))
|
|
|
|
const httpServer: HttpServerLike = (
|
|
((config.server.use == 'http') && http.createServer(app)) ||
|
|
((config.server.use == 'https') && https.createServer(config.server.https, app)) ||
|
|
http.createServer(app)
|
|
)
|
|
const io = new SocketIo.Server(httpServer, {
|
|
|
|
})
|
|
|
|
ApiManager.initServer(httpServer, io)
|
|
ApiManager.initEvents()
|
|
ApiManager.initAllApis()
|
|
|
|
httpServer.listen(config.server.listen)
|
|
console.log(chalk.yellow("===== TheWhiteSilk Server ====="))
|
|
console.log(chalk.green("API & Web 服務已經開始運作"))
|
|
|
|
const rl = readline.createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
})
|
|
rl.on('line', async (text) => {
|
|
|
|
})
|