|
@@ -2,19 +2,28 @@ import express from "express";
|
|
|
import path from "path";
|
|
|
import bodyParser from 'body-parser'
|
|
|
import * as fs from "fs";
|
|
|
+import { fileURLToPath } from 'url';
|
|
|
import fileUpload from 'express-fileupload'
|
|
|
|
|
|
+const __filename = fileURLToPath(import.meta.url);
|
|
|
+const __dirname = path.dirname(__filename);
|
|
|
+
|
|
|
const staticDir = path.resolve(__dirname, "test");
|
|
|
+const publicDir = path.resolve(__dirname, "../dist");
|
|
|
|
|
|
-console.log(staticDir);
|
|
|
let startup = false;
|
|
|
-export async function createServer(port: number) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+export async function createServer(port) {
|
|
|
if (startup) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
const app = express();
|
|
|
app.use(express.static(staticDir));
|
|
|
+ console.log(publicDir)
|
|
|
+ app.use(express.static(publicDir));
|
|
|
app.use(bodyParser({ limit: '200mb' }))
|
|
|
app.use(fileUpload({createParentPath: true}))
|
|
|
app.listen(port);
|
|
@@ -36,7 +45,7 @@ export async function createServer(port: number) {
|
|
|
})
|
|
|
|
|
|
app.post("/:sceneCode/upload", (req, res) => {
|
|
|
- const file = (req as any).files.file
|
|
|
+ const file = (req).files.file
|
|
|
const relUrl = `/attach/upload/${file.name}`
|
|
|
const absUrl = path.resolve(staticDir, `./${req.params.sceneCode}/${relUrl}`)
|
|
|
console.log("上传图片完成路径为", relUrl)
|