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

标签 node.js macos express vue.js lsof

我的环境: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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="65080025081c0008040c094b060a08" rel="noreferrer noopener nofollow">[email protected]</a>
? 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/

相关文章:

javascript - Express.js 删除请求

Node.js - 通过 HTTPS 发出请求时仅与代理服务器通信

node.js - 如何使用 ocif 创建 Git 风格的子命令?

objective-c - 如何在 OS X 上的 Objective C/C 中获取总 CPU 空闲时间?

objective-c - WebView (webkit) "Look Up In Dictionary"UI 错误 - Mac App

javascript - res.redirect 中未定义 - express、request、fs、node-uuid、path 和 multer

node.js - Linux 上的 Node 语法错误,但不是窗口

javascript - NodeJS 只是挂起,没有错误,没有崩溃

c - Mac OS X 中的 makefile 缺少分隔符

javascript - 什么是 NODE_ENV 以及如何在 Express 中使用它?