diff --git a/index.html b/index.html
new file mode 100644
index 0000000..54ef1b7
--- /dev/null
+++ b/index.html
@@ -0,0 +1,4 @@
+
+
+
DEMO
+
\ No newline at end of file
diff --git a/index.js b/index.js
index cc37b41..f904ee8 100644
--- a/index.js
+++ b/index.js
@@ -7,10 +7,11 @@ import random from 'string-random'
import formidable from 'formidable'
import crypto from 'crypto'
import HUB from './fmhub.js'
+import { createServer } from 'vite'
const md5 = (str) => crypto.createHash('md5').update(str).digest('hex')
-const databases = new Map() // 所有数据库
-const FM = new HUB() // 频道消息分发器
+const databases = new Map() // 所有数据库
+const FM = new HUB() // 频道消息分发器
const messagelist = new Map() // 消息队列的nedb存储
const db = (name) => (databases.get(name) || function () {
@@ -397,17 +398,22 @@ const db_compact = function (req, res) {
// 读取对象列表
function index_get(req, res) {
- // 返回对象列表
let list = []
- databases.forEach((value, key) => {
- list.push(key)
- })
+ databases.forEach((value, key) => list.push(key))
res.json(list)
}
const app = expressWs(express()).app
const ServerSentEventsClient = {}
+// 开发模式下使用 Vite
+if (process.argv.includes('--dev')) {
+ const vite = await createServer({ server: { middlewareMode: 'html' } })
+ app.use(vite.middlewares)
+} else {
+ app.use(express.static('dist'))
+}
+
// Server-Sent Events (发送版本号来决定是否接收更新?)
app.use((req, res, next) => {
if (req.get('Accept') === 'text/event-stream') {
diff --git a/package.json b/package.json
index 02c5a56..e30c1c8 100644
--- a/package.json
+++ b/package.json
@@ -19,10 +19,11 @@
"string-random": "^0.1.3"
},
"scripts": {
- "dev": "nodemon --watch index.js index.js",
+ "dev": "nodemon --watch index.js index.js --dev",
"start": "node index.js"
},
"devDependencies": {
+ "concurrently": "^8.2.2",
"nodemon": "^3.1.0",
"vite": "^5.2.11"
}