如何将auth0应用程序部署到bluemix

时间:2016-12-04 06:23:23

标签: node.js ibm-cloud

我正在使用auth0.com的示例项目来自定义应用的登录页面并启用社交媒体登录。但是当我尝试将其部署到bluemix时遇到一些问题。 我关注的视频教程是https://www.youtube.com/watch?v=sHhNoV-sS_I&t=559s 但是示例项目与视频中的项目有点不同。它需要命令“npm serve”才能运行它。当我使用cf push推送我的项目时,它显示noappdecked。如何将项目部署到bluemix? app.js代码和html代码就像

<!DOCTYPE html>
<html>
  <head>
    <title>Auth0-VanillaJS</title>
    <meta charset="utf-8">

    <!-- Auth0 lock script -->
    <script src="//cdn.auth0.com/js/lock/10.3.0/lock.min.js"></script>
    <script src="auth0-variables.js"></script>

    <script src="app.js"></script>

    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body>
    <img alt="avatar" id="avatar" style="display:none;">
    <p>Welcome <span id="nickname"></span></p>
    <button type="submit" id="btn-login">Sign In</button>
    <button type="submit" id="btn-logout" style="display:none;">Sign Out</button>
  </body>

window.addEventListener('load', function() {

  var lock = new Auth0Lock(AUTH0_CLIENT_ID, AUTH0_DOMAIN);

  // buttons
  var btn_login = document.getElementById('btn-login');
  var btn_logout = document.getElementById('btn-logout');

  btn_login.addEventListener('click', function() {
    lock.show();
  });

  btn_logout.addEventListener('click', function() {
    logout();
  });

  lock.on("authenticated", function(authResult) {
    lock.getProfile(authResult.idToken, function(error, profile) {
      if (error) {
        // Handle error
        return;
      }
      localStorage.setItem('id_token', authResult.idToken);
      // Display user information
      show_profile_info(profile);
    });
  });

  //retrieve the profile:
  var retrieve_profile = function() {
    var id_token = localStorage.getItem('id_token');
    if (id_token) {
      lock.getProfile(id_token, function (err, profile) {
        if (err) {
          return alert('There was an error getting the profile: ' + err.message);
        }
        // Display user information
        show_profile_info(profile);
      });
    }
  };

  var show_profile_info = function(profile) {
    var avatar = document.getElementById('avatar');
    document.getElementById('nickname').textContent = profile.nickname;
    btn_login.style.display = "none";
    avatar.src = profile.picture;
    avatar.style.display = "block";
    btn_logout.style.display = "block";
  };

  var logout = function() {
    localStorage.removeItem('id_token');
    window.location.href = "/";
  };

  retrieve_profile();
});

1 个答案:

答案 0 :(得分:1)

您将使用https://console.ng.bluemix.net/docs/runtimes/nodejs/index.html#nodejs_runtime中记录的package.json方法,首先将serve包声明为您的某个依赖项,然后指出scripts.start脚本应该执行的操作(运行npm serve)。您可以使用npm inithttps://docs.npmjs.com/cli/init)创建一个起始package.json文件,如果您还没有。{/ p>