javascript - Electron 如何将数据从 Node 重定向到 Angular 7

标签 javascript node.js angular electron

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

回调重定向工作正常

index.js( Node )

//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( Electron )

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 中时,我可以调用 Node 函数,但无法将数据重定向到 Angular

我尝试使用 file:///并且它也不起作用,它也不会给出错误

感谢您的帮助

最佳答案

我认为无论授权是否通过,你都必须返回 JSON 响应并根据 JSON 在 Electron 应用程序中做出决定。因为 Angular 起点及其服务是 Electron 应用程序,我认为你不能以这种方式重定向。

关于javascript - Electron 如何将数据从 Node 重定向到 Angular 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55255660/

相关文章:

javascript - 为什么 IE 不显示此 alert()?

javascript - 将函数数组传递给异步并行

node.js - 如何在 alpine :3. 8 中安装 Nodejs 8.12?

angular - 如何在 ngx-bootstrap systemjs 中导入模态服务

angular - 无法调试模块 myapp/public/app/app.module.ts 的元数据版本不匹配,发现版本 3,预期版本 4

node.js - Fastify 服务 Angular6 应用程序

javascript - 下拉列表不起作用

javascript - 搜索邮件按钮是如何实现的?

javascript - NestJs - 如何在拦截器上获取请求正文

node.js - Node +谷歌街景: How to check if a Street View is available in a certain radius