我们使用的是角5.2.8和nguniversal/快递引擎5.0.0-beta.6,我们使用的是外部支付服务。支付系统要求一个表单被张贴到他们的网址,并有一个输入的callbackURL。
来自该请求的回调会向我们发送带有数据的POST请求。我们需要用用户凭据将数据发布到后端。从角度上说,我们不能接收邮寄请求。
我曾尝试过一些解决方案,但到目前为止,这些方案都没有奏效:
我需要将回调post的内容发送到客户端,或者将用户凭据传递给服务器端。
发布于 2018-04-05 10:17:40
你的第一种方法应该有效。要真正通用,您可以向您的角度通用应用程序提供快速请求,以便需要请求值的组件/服务可以访问它
server.ts
app.engine('html', (_, options, callback) => {
renderModuleFactory(AppServerModuleNgFactory, {
// Our index.html
document: template,
url: options.req.path,
extraProviders: [
{
provide: 'httpRequest',
useValue: options.req,
}
]
}).then(html => {
callback(null, html);
});
});
//Handle your post
app.post('/yourpostUrl', (req, res) => {
res.render(join(DIST_FOLDER, 'browser', 'index.html'), {req});
});
然后提供请求角侧。不要忘记将其作为可选的,这样它就不会引发错误客户端。
component.ts
constructor(@Optional() @Inject('httpRequest') private httpRequest: any)
{
//here you can use httpRequest's valuesy
}
发布于 2018-04-01 19:23:17
在一个角通用项目中,在server.ts文件中,我们编写了以下类型的代码。
因此,基本上,我们将浏览器重定向到所有角路由的index.html。但是,从/api/*
开始的URL被排除在API下面。似乎您需要以/api/*
开头的回调URL,在那里您需要一个HTTP来处理调用。
app.get('/api/*', (req, res) => {
});
// Server static files from /browser
app.get('*.*', express.static(join(DIST_FOLDER, 'browser')));
// All regular routes use the Universal engine
app.get('*', (req, res) => {
res.render(join(DIST_FOLDER, 'browser', 'index.html'), { req });
});
https://stackoverflow.com/questions/49572873
复制相似问题