1234567891011121314151617181920212223242526272829303132333435 |
- import express from "express";
- import path from "path";
- import bodyParser from 'body-parser'
- import * as fs from "fs";
- const staticDir = path.resolve(__dirname, "test");
- console.log(staticDir);
- let startup = false;
- export async function createServer(port: number) {
- if (startup) {
- return;
- }
- const app = express();
- app.use(express.static(staticDir));
- app.use(bodyParser())
- app.listen(port);
- startup = true;
- app.use((req, res, next) => {
- const paths = req.url.split("/")
- const scene = paths[1]
- const filename = paths[paths.length - 1]
- const p = path.resolve(staticDir, scene, "./attach", filename)
- console.log(p, req.body)
- fs.writeFileSync(p, JSON.stringify(req.body))
- res.json({code: 0, msg: 'ok'})
- })
- console.log("模拟环境已开启");
- }
|