简体   繁体   English

使用AngularJS,Parse-Server和Heroku的混合内容出现问题

[英]Issue with mixed content using AngularJS, Parse-Server, and Heroku

I have a node server running parse-server that I have hosted on Heroku using the free tier. 我有一个运行解析服务器的节点服务器,该服务器使用免费层托管在Heroku上。 I built a web app using AngularJS that retrieves data from the server. 我使用AngularJS构建了一个Web应用程序,该应用程序从服务器检索数据。 After developing it locally I also hosted the webapp on Heroku, and for some reason I get a mixed content warning for all my images that look like this: 在本地进行开发后,我还将webapp托管在Heroku上,由于某种原因,我收到的所有图像的混合内容警告如下:

Mixed Content: The page at 'https:// MYWEBAPP.herokuapp.com' was loaded over HTTPS, but requested an insecure image 混合内容:“ https:// MYWEBAPP.herokuapp.com”上的页面已通过HTTPS加载,但请求的图像不安全
'http:// MYPARSESERVER.herokuapp.com/parse/files/SOMEIMAGE.jpg'. “ http:// MYPARSESERVER.herokuapp.com/parse/files/SOMEIMAGE.jpg”。 This content should also be served over HTTPS. 此内容也应通过HTTPS提供。

My parse-server is using https, but for some reason just requests for files seem to go through http. 我的解析服务器使用的是https,但是出于某种原因,对文件的请求似乎只通过http。

Since this is my first time building and hosting the entire stack, I'm not entirely sure if this is an issue with my Angular app, my parse-server configuration, or just a heroku setting. 由于这是我第一次构建并托管整个堆栈,因此我不确定Angular应用程序,解析服务器配置还是仅是heroku设置是否存在此问题。

If someone has any ideas as to where the problem could potentially be I can provide code snippets to help clarify. 如果有人对问题可能在哪里有任何想法,我可以提供代码片段以帮助阐明。 Thanks for the help! 谢谢您的帮助!

Code samples: 代码示例:

In app.js in my angular app: 在我的角度应用程序的app.js中:

function parseInit($rootScope) {
    Parse.initialize("MY_APP_ID");
    Parse.serverURL = 'https://MY_PARSE_SERVER.herokuapp.com/parse';

    $rootScope.currentUser = Parse.User.current();
}

An example of retrieving data from the backend, including the File objects that seems to be causing the problem: 从后端检索数据的示例,包括似乎引起问题的File对象:

function getEvents() {
   let q = $q.defer();

   let Event = Parse.Object.extend('Event');
   let query = new Parse.Query(Event);

   query
     .include('poster')
     .find({
       success: (events) => {
         q.resolve(events);
       },
       error: (object, error) => {
         q.reject(error);
       }
     });

   return q.promise;
 }

In app.js in my parse-server: 在我的解析服务器中的app.js中:

const express = require('express');
const ParseServer = require('parse-server').ParseServer;
const ParseDashboard = require('parse-dashboard');
const path = require('path');
const env = require('./env.json');

var node_env = process.env.NODE_ENV || "development";
var config = env[node_env];

var api = new ParseServer({
   databaseURI: process.env.MONGODB_URI || config.databaseUri,
   cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
   appId: MY_APP_ID,
   masterKey: MY_MASTER_KEY,
   serverURL: process.env.SERVER_URL || config.serverUrl, 
   facebookAppIds: ["MY_FACEBOOK_APP_ID"],
   revokeSessionOnPasswordReset: true
});

var dashboard = new ParseDashboard({
   "apps": [{
      "serverURL": process.env.SERVER_URL || config.serverUrl,
      "appId": config.appId,
      "masterKey": config.masterKey,
      "appName": "api",
   }]
});

var app = express();

// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
app.use("/dashboard", dashboard)

var port = process.env.PORT || 1337;
app.listen(port, function() {
  console.log('Running on port ' + port + '.');
});

process.env.SERVER_URL is passed as by my heroku set up and is currently https:// MY_PARSE_SERVER.herokuapp.com/parse process.env.SERVER_URL由我的heroku设置传递,当前为https:// MY_PARSE_SERVER.herokuapp.com/parse

This question is pretty vague, your issue could be anywhere in the stack or more involved with the overall application configuration. 这个问题非常模糊,您的问题可能在堆栈中的任何地方,或者与整个应用程序配置有关。

Assuming you've properly configured everything server-side... 假设您已经正确配置了服务器端的所有内容...

From the AngularJS side, I would look anywhere you have a <image> (from your error message) or <script> tag in a template and ensure that you're requesting the resource using https and not http. 从AngularJS的角度来看,我会在模板中有<image> (来自错误消息)或<script>标记的任何地方查找,并确保您使用https而不是http请求资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM