We have an Angular 2 application that processes HTTP requests in the .net Web API service. Both Angular 2 applications and the API are located in IIS.
The client uses webpack to replace the hot module, binding, etc., and also uses preprocessing of the web server server using NodeJS
I am having a problem with http requests that are made as part of a preliminary application to the server. The API requires Windows authentication for all requests, and server-side requests fail because the requests are not authenticated. It appears that node does not provide the appropriate header / user tokens.
For information, this is my webpack configuration:
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
module.exports = (env) => {
const isDevBuild = !(env && env.prod);
const sharedConfig = {
stats: { modules: false },
context: __dirname,
resolve: { extensions: [ '.js', '.ts' ] },
output: {
filename: '[name].js',
publicPath: '/dist/'
},
module: {
rules: [
{ test: /\.ts$/, include: /ClientApp/, use: ['awesome-typescript-loader?silent=true', 'angular2-template-loader'] },
{ test: /\.html$/, use: 'html-loader?minimize=false' },
{ test: /\.css$/, use: [ 'to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
]
},
plugins: [new CheckerPlugin()]
};
const clientBundleOutputDir = './wwwroot/dist';
const clientBundleConfig = merge(sharedConfig, {
module: {
loaders: [
{
test: /config.js$/,
loader: "file?name=[config.js]&context=./dist/"
}
]
},
entry: { 'main-client': './ClientApp/boot-client.ts' },
output: { path: path.join(__dirname, clientBundleOutputDir) },
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
})
].concat(isDevBuild ? [
new webpack.SourceMapDevToolPlugin({
filename: '[file].map',
moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]')
})
] : [
new webpack.optimize.UglifyJsPlugin()
])
});
const serverBundleConfig = merge(sharedConfig, {
resolve: { mainFields: ['main'] },
entry: { 'main-server': './ClientApp/boot-server.ts' },
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./ClientApp/dist/vendor-manifest.json'),
sourceType: 'commonjs2',
name: './vendor'
})
],
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, './ClientApp/dist')
},
target: 'node',
devtool: 'inline-source-map'
});
return [clientBundleConfig, serverBundleConfig];
};
typescript, HTTP- ( ):
public resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<CallDetails> {
let id = route.paramMap.get('id');
let url: string = this.settings.apiUrl + `/api/call/get?id=${id}`;
let options = { withCredentials: true };
return this.http.get(url, options)
.takeUntil(this.ngUnsubscribe)
.map((res: Response) => {
return res.json() || {};
})
.map(data => {
return new CallDetails(data);
})
.catch((res: Response) => {
return this.loadError(res, id);
})
.toPromise<CallDetails>()
.then(callDetails => {
return callDetails
})
}
webpack/nodejs Windows HTTP-? , , ?
.