first commit

This commit is contained in:
锦恢 2024-10-16 16:11:54 +08:00
parent 17c375e9fe
commit 7031d45909
6 changed files with 1197 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
*.exe

6
README.md Normal file
View File

@ -0,0 +1,6 @@
```bash
cd ~/project/Digital-IDE
# 下面这两个项目必须下载到同一个目录下,名字不能变
git clone https://github.com/Digital-EDA/digital-vcd-render
git clone https://github.com/Digital-EDA/digital-vcd-backend
```

1102
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

27
package.json Normal file
View File

@ -0,0 +1,27 @@
{
"name": "digital-vcd-backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "node dist/index.js"
},
"author": "LSTM-Kirigaya",
"license": "MIT",
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^5.0.0",
"@types/morgan": "^1.9.9",
"@types/node": "^22.7.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
},
"dependencies": {
"body-parser": "^1.20.3",
"bson": "^6.8.0",
"cors": "^2.8.5",
"express": "^4.21.1",
"morgan": "^1.10.0"
}
}

47
src/main.ts Normal file
View File

@ -0,0 +1,47 @@
import * as path from 'path';
import * as fs from 'fs';
import express, { Request, Response } from 'express';
import morgan from 'morgan';
import cors from 'cors';
import bodyParser from 'body-parser';
import { BSON } from 'bson';
const corsOptions = {
origin: 'http://localhost:8080',
// 一些旧版浏览器(如 IE11、各种 SmartTV在 204 状态下会有问题
optionsSuccessStatus: 200
};
const app = express();
app.use(express.json());
app.use(cors(corsOptions));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(morgan('dev'));
// 测试项目部署请看 README.md
const rootPath = '../digital-vcd-render/public';
app.get('/', (req: Request, res: Response) => {
res.send('<h1>Hello, World!</h1><br><img src="https://picx.zhimg.com/v2-b4251de7d2499e942c7ebf447a90d2eb_l.jpg"/>');
});
app.post('/save-view', async (req: Request, res: Response) => {
try {
const { file, payload } = req.body;
const savePath = path.join(rootPath, file);
const buffer = BSON.serialize(payload);
fs.writeFileSync(savePath, buffer);
} catch (error) {
console.log('error happen in /save-view, ' + error);
}
})
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});

13
tsconfig.json Normal file
View File

@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist"
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}