首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >节点服务器仅在safari本地主机上加载,而不在chrome的本地主机上加载

节点服务器仅在safari本地主机上加载,而不在chrome的本地主机上加载
EN

Stack Overflow用户
提问于 2019-06-24 07:44:54
回答 1查看 1.4K关注 0票数 0

使用http://localhost:8000的节点服务器只能在Safari中运行,而不能在Chrome中运行。使用127.0.0.1:8000可以在safari和chrome上运行。我搞不懂为什么使用localhost在我的chrome浏览器中不能工作。输入我的终端ping localhost,得到127.0.0.1

在更新到angular 8之前,我的项目工作正常,并且能够在我的本地主机上运行它。我在更新后遇到了一些问题,所以我决定降级回angular 7。从那时起,我只能使用我的IP地址和本地主机来运行我的项目,但只能使用Safari,而不能使用Chrome。你知道问题出在哪里吗?或者怎么解决这个问题?

server.js

代码语言:javascript
复制
const express = require('express');
const app = express();
const path = require('path');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const session = require('express-session');
const mongooseDatabase = require("./server/config/mongoose");
const userRoutes = require('./server/config/routes/users');
const taskRoutes = require('./server/config/routes/tasks');

//Body Parser Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.use(express.static(__dirname + '/dist/todo'));

app.use(session({
    secret:"thisisasecret",
    saveUninitialized:true,
    resave:false,
    cookie: {maxAge:1000}
}))
app.set('trust proxy', 1);
mongoose.connect(mongooseDatabase.database, { useCreateIndex: true, useNewUrlParser:true });

mongoose.connection.on('connected', () => {
    console.log("Connected to database " + mongooseDatabase.database);
})
mongoose.connection.on('error', (err) => {
    console.log("Database database " + err);
})


app.use('/users', taskRoutes, userRoutes);
taskRoutes(app);
userRoutes(app);

app.all("*", (req,res,next) => {
    res.sendFile(path.resolve("./dist/todo/index.html"))
});


app.listen(8000, () => console.log("Running on port 8000"));

全局版本

代码语言:javascript
复制
     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.3.4
Node: 10.16.0
OS: darwin x64
Angular:
...

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.13.4
@angular-devkit/core         7.3.4
@angular-devkit/schematics   7.3.4
@schematics/angular          7.3.4
@schematics/update           0.13.4
rxjs                         6.3.3
typescript                   3.2.4

package.json

代码语言:javascript
复制
{
  "name": "todo",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/material": "^6.2.1",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "angular2-flash-messages": "^3.0.1",
    "body-parser": "^1.19.0",
    "core-js": "^2.5.4",
    "express": "^4.17.1",
    "express-session": "^1.16.2",
    "jquery": "^3.4.1",
    "moment": "^2.24.0",
    "mongoose": "^5.5.15",
    "mongoose-unique-validator": "^2.0.3",
    "path": "^0.12.7",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26",
    "@angular/cdk": "^6.2.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.3",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  },
  "description": "This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.3.3.",
  "main": "index.js",
  "keywords": [],
  "author": "",
  "license": "ISC"
}

如果你需要更多的代码/问题。

angular/cli本地项目版本

代码语言:javascript
复制
     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 7.3.4
Node: 10.16.0
OS: darwin x64
Angular: 7.2.15
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.9
@angular-devkit/build-angular     0.13.9
@angular-devkit/build-optimizer   0.13.9
@angular-devkit/build-webpack     0.13.9
@angular-devkit/core              7.3.9
@angular-devkit/schematics        7.3.4
@angular/cdk                      6.4.7
@angular/cli                      7.3.4
@angular/material                 6.2.1
@ngtools/webpack                  7.3.9
@schematics/angular               7.3.4
@schematics/update                0.13.4
rxjs                              6.3.3
typescript                        3.2.4
webpack                           4.29.0

Error page Error network page

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-09 17:03:41

多亏了@Dave E,我翻阅了以前的帖子,终于找到了答案。他的answer解释了一切

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56728474

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档