黄盛发 6 цаг өмнө
commit
859d3d3987
5 өөрчлөгдсөн 293 нэмэгдсэн , 0 устгасан
  1. 107 0
      .gitignore
  2. 22 0
      cloud/main.js
  3. 21 0
      config.json
  4. 32 0
      package.json
  5. 111 0
      server.ts

+ 107 - 0
.gitignore

@@ -0,0 +1,107 @@
+# Logs
+logs
+*.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+lerna-debug.log*
+
+# Diagnostic reports (https://nodejs.org/api/report.html)
+report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
+
+# Runtime data
+pids
+*.pid
+*.seed
+*.pid.lock
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+*.lcov
+
+# nyc test coverage
+.nyc_output
+
+# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# Bower dependency directory (https://bower.io/)
+bower_components
+
+# node-waf configuration
+.lock-wscript
+
+# Compiled binary addons (https://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directories
+node_modules/
+jspm_packages/
+
+# TypeScript v1 declaration files
+typings/
+
+# TypeScript cache
+*.tsbuildinfo
+
+# Optional npm cache directory
+.npm
+
+# Optional eslint cache
+.eslintcache
+
+# Microbundle cache
+.rpt2_cache/
+.rts2_cache_cjs/
+.rts2_cache_es/
+.rts2_cache_umd/
+
+# Optional REPL history
+.node_repl_history
+
+# Output of 'npm pack'
+*.tgz
+
+# Yarn Integrity file
+.yarn-integrity
+
+# dotenv environment variables file
+.env
+.env.test
+
+# parcel-bundler cache (https://parceljs.org/)
+.cache
+
+# next.js build output
+.next
+
+# nuxt.js build output
+.nuxt
+
+# gatsby files
+.cache/
+# Comment in the public line in if your project uses Gatsby and not Next.js
+# https://nextjs.org/blog/next-9-1#public-directory-support
+# public
+
+# vuepress build output
+.vuepress/dist
+
+# Serverless directories
+.serverless/
+
+# FuseBox cache
+.fusebox/
+
+# DynamoDB Local files
+.dynamodb/
+
+# TernJS port file
+.tern-port
+
+# OS metadata
+.DS_Store
+Thumbs.db

+ 22 - 0
cloud/main.js

@@ -0,0 +1,22 @@
+// Parse Server Cloud Code
+// 这是一个基本的云代码文件,支持自动类生成
+
+Parse.Cloud.define('hello', req => {
+  return 'Hello from Parse Server Cloud Code!';
+});
+
+Parse.Cloud.define('test', req => {
+  return '666!';
+});
+
+// 示例:在用户注册前触发
+Parse.Cloud.beforeSave('User', req => {
+  console.log('Before save User:', req.object);
+});
+
+// 示例:在对象保存后触发
+Parse.Cloud.afterSave('_User', req => {
+  console.log('User saved successfully:', req.object);
+});
+
+// parse-dashboard --appId msq-voc --masterKey Msq2025uqisad --serverURL http://121.37.30.78/parse --appName Web3Dev --port 4041

+ 21 - 0
config.json

@@ -0,0 +1,21 @@
+{
+  "parse": {
+    "appId": "hb-voc",
+    "masterKey": "hb2026pallt",
+    "databaseURI": "postgresql://root:Hongben123!@192.168.0.113/hbvoc",
+    "serverURL": "http://localhost:3000/parse",
+    "masterKeyIps": ["0.0.0.0/0", "::/0"],
+    "allowHeaders": ["*"],
+    "allowOrigin": "*",
+    "port": 3000,
+    "allowClientClassCreation": true,
+    "enableAnonymousUsers": true,
+    "allowExpiredAuthDataToken": false,
+    "revokeSessionOnPasswordReset": false,
+    "cloud": "./cloud/main.js"
+  },
+  "apiLogLevel": "ALL",
+  "environment": "development",
+  "debug": true,
+  "logLevel": "debug"
+}

+ 32 - 0
package.json

@@ -0,0 +1,32 @@
+{
+  "name": "moshengqi-server",
+  "version": "1.0.0",
+  "description": "",
+  "license": "ISC",
+  "author": "",
+  "type": "commonjs",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1",
+    "dev": "bun server.ts"
+  },
+  "dependencies": {
+    "@fmode/studio": "^0.0.12",
+    "@types/cors": "^2.8.19",
+    "@types/express": "^5.0.6",
+    "@types/morgan": "^1.9.10",
+    "@types/multer": "^2.0.0",
+    "cors": "^2.8.6",
+    "express": "^5.2.1",
+    "morgan": "^1.10.1",
+    "multer": "^2.0.2",
+    "parse": "^8.0.3",
+    "xlsx": "^0.18.5",
+    "xmlhttprequest": "^1.8.0"
+  },
+  "devDependencies": {
+    "@types/node": "^25.2.0",
+    "ts-node": "^10.9.2",
+    "typescript": "^5.9.3"
+  }
+}

+ 111 - 0
server.ts

@@ -0,0 +1,111 @@
+
+import express from 'express';
+import { readFileSync } from 'node:fs';
+
+const Parse = require('parse');
+
+Parse.initialize('hb-voc');
+
+Parse.serverURL = 'http://hb-server.fmode.cn/parse';
+
+Parse.masterKey = 'hb2026pallt';
+
+// @ts-ignore
+globalThis.Parse = Parse;
+
+
+
+// 获取配置
+function getConfig() {
+  try {
+    const configPath = process.env.NODE_ENV === 'test' ? './config.test.json' : './config.json';
+    const configContent = readFileSync(configPath, 'utf-8');
+    return JSON.parse(configContent);
+  } catch (error: unknown) {
+    const errorMessage = error instanceof Error ? error.message : 'Unknown error';
+    console.warn('Config file not found, using defaults:', errorMessage);
+    return {
+      parse: {
+        port: 10003,
+        appId: 'hb-voc',
+        serverURL: 'http://hb-server.fmode.cn/parse'
+      }
+    };
+  }
+}
+
+// 初始化 Express 应用
+const app = express();
+
+// 中间件配置
+app.use(express.json());
+app.use(express.urlencoded({ extended: true }));
+// 日志中间件
+app.use((req: any, res: any, next: () => void) => {
+  console.log(`[${new Date().toISOString()}] ${req.method} ${req.path}`);
+  next();
+});
+
+// 健康检查端点
+app.get('/health', (req: any, res: any) => {
+  res.json({
+    status: 'healthy',
+    timestamp: new Date().toISOString(),
+    uptime: process.uptime()
+  });
+});
+
+// 根路由
+app.get('/', (req: any, res: any) => {
+  res.json({
+    message: 'Fmode Server - Gongzuo API',
+    version: '1.0.0',
+    timestamp: new Date().toISOString(),
+    endpoints: ['/api', '/health']
+  });
+});
+
+// 404 处理
+app.use((req: any, res: any) => {
+  res.status(404).json({
+    message: 'Not Found',
+    path: req.path,
+    method: req.method
+  });
+});
+
+// 错误处理中间件
+app.use((err: any, req: any, res: any, next: any) => {
+  console.error('Error:', err);
+  res.status(500).json({
+    message: 'Internal Server Error',
+    error: err.message
+  });
+});
+
+// 启动服务器
+async function startServer() {
+  const config = getConfig();
+  const PORT = process.env.PORT || config.parse?.port || 3000;
+  app.listen(PORT, () => {
+    console.log('\n' + '='.repeat(60));
+    console.log('🚀 Fmode Server - MSQ Started');
+    console.log('='.repeat(60));
+    console.log(`Timestamp: ${new Date().toISOString()}`);
+    console.log('='.repeat(60) + '\n');
+  });
+}
+
+// 优雅关闭
+process.on('SIGTERM', () => {
+  console.log('\n📛 SIGTERM signal received: closing HTTP server');
+  process.exit(0);
+});
+
+process.on('SIGINT', () => {
+  console.log('\n📛 SIGINT signal received: closing HTTP server');
+  process.exit(0);
+});
+
+// 启动服务器
+await startServer();