实现保存恢复功能
This commit is contained in:
parent
b8fc82c33f
commit
d77755a7dd
@ -9,7 +9,6 @@ import bodyParser from 'body-parser';
|
||||
import { BSON } from 'bson';
|
||||
|
||||
const corsOptions = {
|
||||
origin: 'http://localhost:8080',
|
||||
// 一些旧版浏览器(如 IE11、各种 SmartTV)在 204 状态下会有问题
|
||||
optionsSuccessStatus: 200
|
||||
};
|
||||
@ -31,18 +30,17 @@ app.get('/', (req: Request, res: Response) => {
|
||||
|
||||
app.post('/save-view', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const { file, payload } = req.body;
|
||||
console.log(payload);
|
||||
|
||||
const { file, payload } = req.body;
|
||||
const savePath = path.join(rootPath, file);
|
||||
const buffer = BSON.serialize(payload);
|
||||
fs.writeFileSync(savePath, buffer);
|
||||
res.send('success');
|
||||
} catch (error) {
|
||||
console.log('error happen in /save-view, ' + error);
|
||||
res.send('error');
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user