Commit baa95bb6 by linjinhong

添加设备类型实现浏览器打开压缩文件

parent 9de22220
...@@ -350,6 +350,24 @@ ...@@ -350,6 +350,24 @@
ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/" ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/"
``` ```
2025.4.14更新npm安装Electron 项目失败报错问题和解决办法
1.打开npm的配置文件
```shell
npm config edit
```
2.在打开的配置文件空白处将下面几个配置添加上去,注意如果有原有的这几项配置,就修改
```
registry=https://registry.npmmirror.com
electron_mirror=https://cdn.npmmirror.com/binaries/electron/
electron_builder_binaries_mirror=https://npmmirror.com/mirrors/electron-builder-binaries/
```
3、然后关闭该窗口,重启命令行,删除node_modules文件夹,并执行下面命令清除缓存,再重新安装依赖
- 新增 vue-cli方面的plug支持, 即vue-cli-plugin-electron-builder 支持, 主要作用是修改package.json, 并新增一个electron主程序入口文件 src/background.js - 新增 vue-cli方面的plug支持, 即vue-cli-plugin-electron-builder 支持, 主要作用是修改package.json, 并新增一个electron主程序入口文件 src/background.js
```shell ```shell
......
[2025-04-14T18:03:54.627] [INFO] log -
时间:2025-04-14 18:03:54
ip : ::1
host : localhost:3000
响应时间 : 0.32 s
method :GET
url :/checkUpdate?version=1.0.6
token :eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzeXNVc2VyIjp7ImlkIjo0NywiYWNjb3VudCI6IjEyMzQ1NiIsInBhc3N3b3JkIjoiZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2UiLCJzdXBwZXJNYXJrIjoxLCJmYWN0b3J5SWQiOjM0LCJmYWN0b3J5Q29kZSI6IlRlc3QwMDEiLCJzdGF0dXMiOjEsImZhY3RvcnkiOnsiaWQiOjM0LCJiaWFubWEiOiJUZXN0MDAxIiwidGl0bGUiOiJUZXN0IiwidHlwZUlkIjoxNiwibmFtZSI6IjEyMzQ1NiIsIm1vYmlsZSI6IjEyMzQ1NiIsImdvb2RzTnVtYmVyIjowLCJhdXRob3JpemVOdW1iZXIiOjAsInN0YXR1cyI6MX19LCJleHAiOjE3NDQ3MDk3MDl9.iZyGXcBkSaSR-RsoKL-N34lKITZsoeNfm48olQhRoRt7Tc6JUkoF8VFZsvxcpB3lsBvkHEoNYa92uB7zb75OdA
body :{}
状态码 :304
data :{"code":200,"data":{"id":14,"version":"1.0.7","title":"新版本更新!","content":"1.修复打印机数据传输错误问题","fullUpdate":0,"forcedUpdate":0,"businessType":"production_assistant","createTime":"2025-04-14T09:29:49","updateTime":"2025-04-14T09:29:49","fileList":[{"id":56,"storageType":"local","businessType":"production_assistant","businessId":14,"fileUrl":"/data/upload/erp//app/productionAssistant/1.0.7/css.zip","versionPath":"/data/upload/erp//app/productionAssistant/1.0.7","fileUrlCrc":0,"createTime":"2025-04-14T09:29:49","updateTime":"2025-04-14T09:29:49"}]},"message":"操作成功"}
[2025-04-14T18:06:06.655] [INFO] log -
时间:2025-04-14 18:06:06
ip : ::1
host : localhost:3000
响应时间 : 0.262 s
method :GET
url :/checkUpdate?version=1.0.6
token :eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzeXNVc2VyIjp7ImlkIjo0NywiYWNjb3VudCI6IjEyMzQ1NiIsInBhc3N3b3JkIjoiZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2UiLCJzdXBwZXJNYXJrIjoxLCJmYWN0b3J5SWQiOjM0LCJmYWN0b3J5Q29kZSI6IlRlc3QwMDEiLCJzdGF0dXMiOjEsImZhY3RvcnkiOnsiaWQiOjM0LCJiaWFubWEiOiJUZXN0MDAxIiwidGl0bGUiOiJUZXN0IiwidHlwZUlkIjoxNiwibmFtZSI6IjEyMzQ1NiIsIm1vYmlsZSI6IjEyMzQ1NiIsImdvb2RzTnVtYmVyIjowLCJhdXRob3JpemVOdW1iZXIiOjAsInN0YXR1cyI6MX19LCJleHAiOjE3NDQ3MDk3MDl9.iZyGXcBkSaSR-RsoKL-N34lKITZsoeNfm48olQhRoRt7Tc6JUkoF8VFZsvxcpB3lsBvkHEoNYa92uB7zb75OdA
body :{}
状态码 :304
data :{"code":200,"data":{"id":14,"version":"1.0.7","title":"新版本更新!","content":"1.修复打印机数据传输错误问题","fullUpdate":0,"forcedUpdate":0,"businessType":"production_assistant","createTime":"2025-04-14T09:29:49","updateTime":"2025-04-14T09:29:49","fileList":[{"id":56,"storageType":"local","businessType":"production_assistant","businessId":14,"fileUrl":"/data/upload/erp//app/productionAssistant/1.0.7/css.zip","versionPath":"/data/upload/erp//app/productionAssistant/1.0.7","fileUrlCrc":0,"createTime":"2025-04-14T09:29:49","updateTime":"2025-04-14T09:29:49"}]},"message":"操作成功"}
[2025-04-14T18:06:41.585] [INFO] log -
时间:2025-04-14 18:06:41
ip : ::1
host : localhost:3000
响应时间 : 0.26 s
method :GET
url :/checkUpdate?version=1.0.6
token :eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzeXNVc2VyIjp7ImlkIjo0NywiYWNjb3VudCI6IjEyMzQ1NiIsInBhc3N3b3JkIjoiZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2UiLCJzdXBwZXJNYXJrIjoxLCJmYWN0b3J5SWQiOjM0LCJmYWN0b3J5Q29kZSI6IlRlc3QwMDEiLCJzdGF0dXMiOjEsImZhY3RvcnkiOnsiaWQiOjM0LCJiaWFubWEiOiJUZXN0MDAxIiwidGl0bGUiOiJUZXN0IiwidHlwZUlkIjoxNiwibmFtZSI6IjEyMzQ1NiIsIm1vYmlsZSI6IjEyMzQ1NiIsImdvb2RzTnVtYmVyIjowLCJhdXRob3JpemVOdW1iZXIiOjAsInN0YXR1cyI6MX19LCJleHAiOjE3NDQ3MDk3MDl9.iZyGXcBkSaSR-RsoKL-N34lKITZsoeNfm48olQhRoRt7Tc6JUkoF8VFZsvxcpB3lsBvkHEoNYa92uB7zb75OdA
body :{}
状态码 :304
data :{"code":200,"data":{"id":14,"version":"1.0.7","title":"新版本更新!","content":"1.修复打印机数据传输错误问题","fullUpdate":0,"forcedUpdate":0,"businessType":"production_assistant","createTime":"2025-04-14T09:29:49","updateTime":"2025-04-14T09:29:49","fileList":[{"id":56,"storageType":"local","businessType":"production_assistant","businessId":14,"fileUrl":"/data/upload/erp//app/productionAssistant/1.0.7/css.zip","versionPath":"/data/upload/erp//app/productionAssistant/1.0.7","fileUrlCrc":0,"createTime":"2025-04-14T09:29:49","updateTime":"2025-04-14T09:29:49"}]},"message":"操作成功"}
[2025-04-14T18:09:56.946] [INFO] log -
时间:2025-04-14 18:09:56
ip : ::1
host : localhost:3000
响应时间 : 0.315 s
method :GET
url :/checkUpdate?version=1.0.6
token :eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzeXNVc2VyIjp7ImlkIjo0NywiYWNjb3VudCI6IjEyMzQ1NiIsInBhc3N3b3JkIjoiZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2UiLCJzdXBwZXJNYXJrIjoxLCJmYWN0b3J5SWQiOjM0LCJmYWN0b3J5Q29kZSI6IlRlc3QwMDEiLCJzdGF0dXMiOjEsImZhY3RvcnkiOnsiaWQiOjM0LCJiaWFubWEiOiJUZXN0MDAxIiwidGl0bGUiOiJUZXN0IiwidHlwZUlkIjoxNiwibmFtZSI6IjEyMzQ1NiIsIm1vYmlsZSI6IjEyMzQ1NiIsImdvb2RzTnVtYmVyIjowLCJhdXRob3JpemVOdW1iZXIiOjAsInN0YXR1cyI6MX19LCJleHAiOjE3NDQ3MDk3MDl9.iZyGXcBkSaSR-RsoKL-N34lKITZsoeNfm48olQhRoRt7Tc6JUkoF8VFZsvxcpB3lsBvkHEoNYa92uB7zb75OdA
body :{}
状态码 :304
data :{"code":200,"data":{"id":14,"version":"1.0.7","title":"新版本更新!","content":"1.修复打印机数据传输错误问题","fullUpdate":0,"forcedUpdate":0,"businessType":"production_assistant","createTime":"2025-04-14T09:29:49","updateTime":"2025-04-14T09:29:49","fileList":[{"id":56,"storageType":"local","businessType":"production_assistant","businessId":14,"fileUrl":"/data/upload/erp//app/productionAssistant/1.0.7/css.zip","versionPath":"/data/upload/erp//app/productionAssistant/1.0.7","fileUrlCrc":0,"createTime":"2025-04-14T09:29:49","updateTime":"2025-04-14T09:29:49"}]},"message":"操作成功"}
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
"bignumber.js": "^9.2.1", "bignumber.js": "^9.2.1",
"compressing": "^1.10.1", "compressing": "^1.10.1",
"core-js": "^3.6.4", "core-js": "^3.6.4",
"electron": "^6.1.1",
"electron-builder": "^24.13.3", "electron-builder": "^24.13.3",
"electron-icon-builder": "^2.0.1", "electron-icon-builder": "^2.0.1",
"electron-log": "^5.1.7", "electron-log": "^5.1.7",
...@@ -53,6 +52,7 @@ ...@@ -53,6 +52,7 @@
"@vue/cli-service": "^4.2.0", "@vue/cli-service": "^4.2.0",
"@vue/eslint-config-prettier": "^6.0.0", "@vue/eslint-config-prettier": "^6.0.0",
"babel-eslint": "^10.0.3", "babel-eslint": "^10.0.3",
"electron": "^6.1.12",
"eslint": "^6.7.2", "eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.1.1", "eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-vue": "^6.1.2", "eslint-plugin-vue": "^6.1.2",
......
...@@ -8,7 +8,7 @@ import { autoUpdater } from "electron-updater"; ...@@ -8,7 +8,7 @@ import { autoUpdater } from "electron-updater";
Object.defineProperty(app, "isPackaged", { Object.defineProperty(app, "isPackaged", {
get() { get() {
return true; return true;
} },
}); });
createServer(); createServer();
const isDevelopment = process.env.NODE_ENV !== "production"; const isDevelopment = process.env.NODE_ENV !== "production";
...@@ -16,7 +16,7 @@ const isDevelopment = process.env.NODE_ENV !== "production"; ...@@ -16,7 +16,7 @@ const isDevelopment = process.env.NODE_ENV !== "production";
let win; let win;
let newWindow; let newWindow;
protocol.registerSchemesAsPrivileged([ protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true } } { scheme: "app", privileges: { secure: true, standard: true } },
]); ]);
const winURL = const winURL =
process.env.NODE_ENV === "development" process.env.NODE_ENV === "development"
...@@ -30,19 +30,19 @@ async function createWindow() { ...@@ -30,19 +30,19 @@ async function createWindow() {
icon: "./src/assets/logo.jpg", icon: "./src/assets/logo.jpg",
webPreferences: { webPreferences: {
webSecurity: false, webSecurity: false,
nodeIntegration: true nodeIntegration: true,
} },
}); });
let newWindow = new BrowserWindow({ let newWindow = new BrowserWindow({
fullscreen: false, fullscreen: false,
width: 1000, width: 1000,
height: 1000, height: 1000,
webPreferences: { webPreferences: {
nodeIntegration: true nodeIntegration: true,
//配置预加载脚本文件(preload),此处起名为preloadOther //配置预加载脚本文件(preload),此处起名为preloadOther
//p.s.路径为绝对路径 //p.s.路径为绝对路径
// preload: path.join(__dirname, "./preloadOther.js") // preload: path.join(__dirname, "./preloadOther.js")
} },
}); });
console.log(winURL + "#" + `/design-detail`); console.log(winURL + "#" + `/design-detail`);
//指定副屏幕打开的网页 //指定副屏幕打开的网页
...@@ -52,14 +52,12 @@ async function createWindow() { ...@@ -52,14 +52,12 @@ async function createWindow() {
win = null; win = null;
}); });
ipcMain.on("allPrint", () => { ipcMain.on("allPrint", () => {
// 获取到打印机列表 // 获取到打印机列表
const printers = win.webContents.getPrinters(); const printers = win.webContents.getPrinters();
// 把获取的打印机列表发送给渲染进程 // 把获取的打印机列表发送给渲染进程
win.webContents.send("printName", printers); win.webContents.send("printName", printers);
}); });
ipcMain.on("win-subScreen", (data, v) => { ipcMain.on("win-subScreen", (data, v) => {
if (newWindow) newWindow.webContents.send("getProductionNoInfo", v); if (newWindow) newWindow.webContents.send("getProductionNoInfo", v);
}); });
...@@ -79,29 +77,29 @@ async function createWindow() { ...@@ -79,29 +77,29 @@ async function createWindow() {
win.on("closed", () => { win.on("closed", () => {
win && win.removeAllListeners(); win && win.removeAllListeners();
win = null; win = null;
newWindow && newWindow.close() newWindow && newWindow.close();
newWindow = null; newWindow = null;
}); });
// 自动更新逻辑开始 // 自动更新逻辑开始
autoUpdater.autoDownload = false autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = false; // 应用退出后自动安装 autoUpdater.autoInstallOnAppQuit = false; // 应用退出后自动安装
autoUpdater.on("download-progress", progress => { autoUpdater.on("download-progress", (progress) => {
// 下载进度监听 // 下载进度监听
if (win.isDestroyed()) return; if (win.isDestroyed()) return;
win.webContents.send("update", { win.webContents.send("update", {
speed: Math.ceil(progress.bytesPerSecond / 1000), // 网速 speed: Math.ceil(progress.bytesPerSecond / 1000), // 网速
percent: Math.ceil(progress.percent) // 百分比 percent: Math.ceil(progress.percent), // 百分比
}); });
}); });
autoUpdater.on("error", err => { autoUpdater.on("error", (err) => {
// 下载失败监听 // 下载失败监听
if (win.isDestroyed()) return; if (win.isDestroyed()) return;
win.webContents.send("update-error",err); win.webContents.send("update-error", err);
}); });
autoUpdater.on("update-downloaded", info => { autoUpdater.on("update-downloaded", (info) => {
// 下载完成监听 // 下载完成监听
if (win.isDestroyed()) return; if (win.isDestroyed()) return;
console.log(info, "info"); console.log(info, "info");
...@@ -118,13 +116,12 @@ async function createWindow() { ...@@ -118,13 +116,12 @@ async function createWindow() {
if (win.isDestroyed()) return; if (win.isDestroyed()) return;
autoUpdater.setFeedURL({ autoUpdater.setFeedURL({
provider: "generic", provider: "generic",
url: item.url url: item.url,
}); });
autoUpdater.checkForUpdates().then(res=>{ autoUpdater.checkForUpdates().then((res) => {
console.log(res); console.log(res);
autoUpdater.downloadUpdate() autoUpdater.downloadUpdate();
}) });
}); });
} }
...@@ -151,7 +148,7 @@ app.on("will-quit", () => { ...@@ -151,7 +148,7 @@ app.on("will-quit", () => {
if (isDevelopment) { if (isDevelopment) {
if (process.platform === "win32") { if (process.platform === "win32") {
process.on("message", data => { process.on("message", (data) => {
if (data === "graceful-exit") { if (data === "graceful-exit") {
app.quit(); app.quit();
} }
......
...@@ -14,14 +14,14 @@ axios.defaults.timeout = 12600000; ...@@ -14,14 +14,14 @@ axios.defaults.timeout = 12600000;
const multiparty = require("multiparty"); const multiparty = require("multiparty");
function readEnv() { function readEnv() {
let exePath,configPath let exePath, configPath;
if(process.env.NODE_ENV === "development") { if (process.env.NODE_ENV === "development") {
configPath = path.join(__dirname, "../config/env.json"); configPath = path.join(__dirname, "../config/env.json");
}else{ } else {
exePath = path.dirname(app.getPath("exe")).replace(/\\/g, "/"); exePath = path.dirname(app.getPath("exe")).replace(/\\/g, "/");
configPath = `${exePath}/config/env.json`; configPath = `${exePath}/config/env.json`;
} }
console.log(configPath,__dirname); console.log(configPath, __dirname);
fs.readFile(configPath, "utf-8", (err, data) => { fs.readFile(configPath, "utf-8", (err, data) => {
if (err) { if (err) {
console.error("读取配置文件失败:", err); console.error("读取配置文件失败:", err);
...@@ -33,7 +33,7 @@ function readEnv() { ...@@ -33,7 +33,7 @@ function readEnv() {
visionUrl = config.visionUrl; visionUrl = config.visionUrl;
}); });
} }
readEnv() readEnv();
export default { export default {
writePrintLog: async (req, res) => { writePrintLog: async (req, res) => {
try { try {
...@@ -60,24 +60,25 @@ export default { ...@@ -60,24 +60,25 @@ export default {
const token = req.headers["jwt-token"]; const token = req.headers["jwt-token"];
try { try {
let { let {
data data,
} = await axios.post( } = await axios.post(
`${env}/factory/podJomallOrder/downloadByProduction`,req.body, `${env}/factory/podJomallOrder/downloadByProduction`,
req.body,
{ headers: { "jwt-token": token } } { headers: { "jwt-token": token } }
); );
console.log(data); console.log(data);
let files = []; let files = [];
if (data.code === 200) { if (data.code === 200) {
files = data.data; files = data.data;
files = files.map(el => { files = files.map((el) => {
return { url: `${fileEnv}${el}` }; return { url: `${fileEnv}${el}` };
}); });
console.log(files); console.log(75, files);
downloadImage(files) downloadImage(files)
.then(data => { .then((data) => {
res.json({ code: 200, data }); res.json({ code: 200, data });
}) })
.catch(err => { .catch((err) => {
res.json({ code: 500, msg: err }); res.json({ code: 500, msg: err });
}); });
} else { } else {
...@@ -96,7 +97,7 @@ export default { ...@@ -96,7 +97,7 @@ export default {
`${env}/factory/podJomallOrderProduct/getSubOrderByThirdSubOrderNumber`, `${env}/factory/podJomallOrderProduct/getSubOrderByThirdSubOrderNumber`,
{ {
params: q, params: q,
headers: { "jwt-token": token } headers: { "jwt-token": token },
} }
); );
res.json(data); res.json(data);
...@@ -120,7 +121,7 @@ export default { ...@@ -120,7 +121,7 @@ export default {
const token = req.headers["jwt-token"]; const token = req.headers["jwt-token"];
try { try {
let { let {
data data,
} = await axios.post( } = await axios.post(
`${env}/factory/podJomallOrderProduct/completeDelivery`, `${env}/factory/podJomallOrderProduct/completeDelivery`,
req.body, req.body,
...@@ -153,7 +154,7 @@ export default { ...@@ -153,7 +154,7 @@ export default {
console.log("success"); console.log("success");
res.json({ res.json({
code: 200, code: 200,
msg: q.productionNo + ".zip" + "已下载到桌面" msg: q.productionNo + ".zip" + "已下载到桌面",
}); });
}) })
.on("error", () => { .on("error", () => {
...@@ -195,8 +196,8 @@ export default { ...@@ -195,8 +196,8 @@ export default {
code: 200, code: 200,
data: { data: {
fileName, fileName,
url: path.join(process.cwd(), "./print/Input/" + fileName) url: path.join(process.cwd(), "./print/Input/" + fileName),
} },
}); });
} }
}); });
...@@ -246,10 +247,10 @@ export default { ...@@ -246,10 +247,10 @@ export default {
writeProfileXml(body); // 写入xml文件 writeProfileXml(body); // 写入xml文件
// GTXproCMD.exe print -X "Profile\\CO12.xml" -I "Input\\sample.png" -A "Output\\pO12.arxp" -S 03000400 -L 02540254 // GTXproCMD.exe print -X "Profile\\CO12.xml" -I "Input\\sample.png" -A "Output\\pO12.arxp" -S 03000400 -L 02540254
toSend(body) toSend(body)
.then(r => { .then((r) => {
res.send({ code: 200, msg: "操作成功" }); res.send({ code: 200, msg: "操作成功" });
}) })
.catch(err => { .catch((err) => {
res.send({ code: 500, msg: err }); res.send({ code: 500, msg: err });
}); });
}, },
...@@ -288,12 +289,12 @@ export default { ...@@ -288,12 +289,12 @@ export default {
fs.unlinkSync(from); fs.unlinkSync(from);
res.json({ code: 200, msg: "更新成功" }); res.json({ code: 200, msg: "更新成功" });
}) })
.catch(err => { .catch((err) => {
res.json({ code: 500, msg: err.message }); res.json({ code: 500, msg: err.message });
}); });
}); });
} catch (err) { } catch (err) {
res.json({ code: 500, msg: err.message }); res.json({ code: 500, msg: err.message });
} }
} },
}; };
import express from "express"; import express from "express";
import router from "./routes/index.js"; import router from "./routes/index.js";
import {logMiddleWare} from './utils/log' import { logMiddleWare } from "./utils/log";
const { app } = require("electron");
import path from "path"; // 引入 path 模块
const PORT = 3000; const PORT = 3000;
const printPORT = 3030;
// 获取应用程序的安装目录
let exePath = path.dirname(app.getPath("exe"));
export const createServer = () => { export const createServer = () => {
const webApp = express(); const webApp = express();
const printApp = express();
//webApp.use(logger("./logs")); //webApp.use(logger("./logs"));
webApp.use( logMiddleWare()); webApp.use(logMiddleWare());
webApp.use(express.json()); webApp.use(express.json());
webApp.use(express.urlencoded({ extended: false })); webApp.use(express.urlencoded({ extended: false }));
webApp.use("/", router); webApp.use("/", router);
// catch 404 // catch 404
webApp.use((req, res) => { webApp.use((req, res) => {
res.status(404).send("Sorry! 404 Error."); res.status(404).send("Sorry! 404 Error.");
...@@ -26,11 +32,40 @@ export const createServer = () => { ...@@ -26,11 +32,40 @@ export const createServer = () => {
res.status(err.status || 500); res.status(err.status || 500);
res.json({ res.json({
message: err.message, message: err.message,
error: err error: err,
}); });
}); });
webApp.set("port", PORT); webApp.set("port", PORT);
webApp.listen(PORT, () => console.log(`App listening on port ${PORT}`)); webApp.listen(PORT, () => console.log(`App listening on port ${PORT}`));
console.log("__dirname", __dirname);
// 判断环境变量来决定使用哪种路径
console.log(48, process.env.NODE_ENV);
if (process.env.NODE_ENV === "development") {
// 在开发环境中,假设静态文件存放在本地的 "print/input" 目录中
printApp.use(express.static(path.join(__dirname, "..", "print", "input")));
} else {
// 在生产环境中,静态文件会存放在应用安装目录中
printApp.use(express.static(path.join(exePath, "print", "input")));
}
// printApp 的 404 错误处理(如果需要)
printApp.use((req, res) => {
res.status(404).send("Sorry! 404 Error.");
});
// printApp 错误处理中间件(如果需要)
printApp.use((err, req, res) => {
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};
res.status(err.status || 500);
res.json({
message: err.message,
error: err,
});
});
// 启动服务器
printApp.listen(printPORT, () => {
console.log(`Express server running at http://localhost:${printPORT}`);
});
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment