gpt4 book ai didi

node.js - 如何终止在 localhost :8080 (MacOS) 上运行的 VueJS 应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 23:17:58 26 4
gpt4 key购买 nike

我的环境:MacOS Mojave

我使用

从他们的模板创建了一个 VueJS 应用程序
vue init pwa frontend
? Project name frontend
? Project short name: fewer than 12 characters to not be truncated on homescreens (default: same as name)
? Project description A Vue.js project
? Author me@myemail.com
? Vue build runtime
? Install vue-router? Yes
? Use ESLint to lint your code? No
? Setup unit tests with Karma + Mocha? No
? Setup e2e tests with Nightwatch? No

yarn
yarn dev

效果很好。该页面在 localhost:8080 上运行,并在按 ctrl-c 时关闭。

然后我将其构建用于生产

yarn build

我编写了一个快速 JS 服务器来启动 dist/文件夹中的内容,以查看构建后的样子。

const ora = require('ora')
const chalk = require('chalk');
const express = require('express');
const port = process.env.PORT || 8080;
const app = express();
const spinner = ora(chalk.yellow("Your application is starting..."));
spinner.start();

var delay = ( function() {
var timer = 0;
return function(callback, ms) {
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();

app.use(express.static(__dirname + "/dist/"));
app.get(/.*/, function(req, res) {
res.sendFile(__dirname + "/dist/index.html");
});

app.listen(port);

delay(function() {
app.use(express.static(__dirname + "/dist/"));
app.get(/.*/, function(req, res) {
res.sendFile(__dirname + "/dist/index.html");
});
}, 3000);

spinner.stop();
console.log(chalk.cyan("Your application is running here: ") + ("http://localhost:8080"));

我运行服务器node server.js

但是,当我按 ctrl-c 时,它会终止脚本,但应用程序仍在 localhost:8080 上运行

我已经尝试过sudo lsof -i tcp:8080netstat -vanp tcp | grep 8080他们都没有返回任何东西。这给我留下了以下问题:如何阻止它监听端口 8080?

最佳答案

如果有人想知道,我发现了问题。我必须转到 chrome://serviceworker-internals 和 chrome://appcache-internals 。我搜索了 localhost:8080 并杀死了那些 serviceworkers。

我希望这对接下来发生这种情况的人有所帮助!

关于node.js - 如何终止在 localhost :8080 (MacOS) 上运行的 VueJS 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53015155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com