【问题标题】:How to kill VueJS application running on localhost:8080 (MacOS)如何杀死在 localhost:8080 (MacOS) 上运行的 VueJS 应用程序
【发布时间】:2018-10-26 19:26:05
【问题描述】:

我的环境: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 上侦听?

【问题讨论】:

  • 试试这个命令lsof -ti:8080 | xargs kill -9
  • 不起作用,因为 lsof -ti:8080 不返回任何结果。
  • 你如何确定它仍在运行?
  • 我要去localhost:8080,应用程序仍在运行。
  • 你能试试npx kill-port 8080吗?

标签: node.js macos express vue.js lsof


【解决方案1】:

如果有人想知道,我发现了问题。我不得不去chrome://serviceworker-internalschrome://appcache-internals。我搜索了localhost:8080 并杀死了那些服务人员。

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

【讨论】:

    猜你喜欢
    • 2011-06-27
    • 1970-01-01
    • 2016-02-19
    • 2015-06-16
    • 2019-11-24
    • 2010-10-28
    • 2013-07-09
    • 2015-08-01
    • 1970-01-01
    相关资源
    最近更新 更多