【问题标题】:electron how to redirect data from node to angular 7电子如何将数据从节点重定向到角度7
【发布时间】:2019-03-20 07:38:35
【问题描述】:

我生成了一个 Angular 7 应用程序,它在 http://localhost:4200 上运行 我在 Node JS 中有一个应用程序,负责在 Facebook 上对用户进行身份验证,运行在 http://localhost:3000

回调重定向工作正常

index.js(节点)

//facebook
const FACEBOOK_APP_ID = 'xxx';
const FACEBOOK_APP_SECRET = 'xxx';

passport.use(new FacebookStrategy({
  clientID: FACEBOOK_APP_ID,
  clientSecret: FACEBOOK_APP_SECRET,
  callbackURL: "/auth/facebook/callback"
},
function (accessToken, refreshToken, profile, cb) {
  return cb(null, profile, accessToken);
}
));

app.get('/auth/facebook',
  passport.authenticate('facebook'));


app.get('/auth/facebook/callback',
  passport.authenticate('facebook', {
    failureRedirect: 'http://localhost:4200/login'
  }),
  function (req, res) {
    res.redirect('http://localhost:4200/main' + req.authInfo);
  });

const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`server en port ${port}`)
});

app.modules.ts

const appRoutes: Routes = [{
    path: '',
    component: LoginComponent,
  },
  {
    path: 'login',
    component: LoginComponent,
  },
  {
    path: 'main/:token',
    component: MainComponent,
  },
  {
    path: '',
    redirectTo: 'login',
    pathMatch: 'full'
  },
  {
    path: '**',
    component: Error404Component
  },
];

ma​​in.js(电子)

const url = require('url');
const path = require('path');
const fs = require('fs');
const {
  app,
  BrowserWindow,
  Menu,
  dialog
} = require('electron');
const openAboutWindow = require('about-window').default;

let win;
let menu;

const application_menu = [{
    label: 'Archivo',
    submenu: [{
      label: 'Salir',
      accelerator: 'Command+Q',
      click: () => {
        app.quit();
      }
    }, ]
  },
  {
    label: 'Configuración',
    submenu: [{
      label: 'Carpetas',
      accelerator: 'CommandOrControl+o',
      click: () => {
        openFolderDialog()
      }
    }]
  },
  {
    label: 'Ayuda',
    submenu: [{
        label: 'Documentación',
        click() {
          require('electron').shell.openExternal('https://electronjs.org')
        }
      },
    ]
  }
];


function createWindow() {
  let nd = require('./api/index.js');

  menu = Menu.buildFromTemplate(application_menu);
  Menu.setApplicationMenu(menu);

  win = new BrowserWindow({
    width: 800,
    height: 600,
    show: false,
    icon: __dirname + '/icons/batman.ico'
  });

  win.loadFile('./dist/UI/index.html');

  win.webContents.openDevTools()

  win.once('ready-to-show', () => {
    win.show()
  })

  win.on('closed', function () {
    win = null;
  });
};

app.on('ready', createWindow);

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit()
  }
});

app.on('activate', () => {
  if (win === null) {
    createWindow()
  }
});

尝试将其包含在 Electron 中时,我可以调用节点函数,但无法将数据重定向到 angular

我尝试使用文件:///它也不起作用,它也不会出错

感谢您的帮助

【问题讨论】:

  • 您如何在电子中显示角度内容?你可以添加一个样本吗?你在使用网络视图吗?或者你将角度整合到电子中?

标签: javascript node.js angular electron


【解决方案1】:

我认为您必须返回 JSON 响应并根据 JSON 在电子应用程序中做出决定,授权是否通过。因为角度的起点是电子应用程序,我认为你不能这样重定向。

【讨论】:

  • CORS 请求外部重定向不允许服务器响应 CORS 请求,将 HTTP 重定向到与原始请求不同来源的 URL,这是不允许的在 CORS 请求期间。要解决此问题,请更新您的代码以使用重定向报告的新 URL,从而避免重定向。 Read More
猜你喜欢
  • 2018-03-24
  • 1970-01-01
  • 2015-09-18
  • 2019-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-10
  • 1970-01-01
相关资源
最近更新 更多