I integrate AngularJS into hackathon-starter. This was done as I mentioned it here with the following tags test.html and test.controller.js
<div>
The record: {{record}}
</div>
<div align="right">
<button class="btn btn-lg btn-primary" ng-click="createRecord()" onclick="window.location.href='/order/shipping'">
<i class=""> Create record</i>
</button>
</div>
test.controller.js
(function () {
'use strict';
var injectParams = ['$scope', '$location', '$http'];
function TestController($scope, $location, $http) {
$scope.record = {
interId: 1,
sku: '107k',
category: 'Useful'
};
function createRecord(record) {
return $http.post('/order/create', record).then(function (response) {
return response.data;
})
}
$scope.createRecord = function () {
var record = $scope.record;
createRecord(record)
.then(function (data) {
if (data.success) {
return $location.url('/shipping');
}
alert('Something wrong...');
});
}
};
TestController.$inject = injectParams;
angular.module('miniApp')
.controller('TestController', TestController);
}());
It works if csrf is set to false, for example:
app.use(lusca({
csrf: false,
xframe: 'SAMEORIGIN',
xssProtection: true }));
If csrf is set to true, then there is an error:
Error: CSRF token is missing
One of the solutions to this problem is to put a request on the path "/ order / create" to the lusca configuration, for example:
app.post('/order/create', passportConf.isAuthenticated, orderController.postCreateOrder);
app.use(lusca({
csrf: true,
...
But this solution is not very elegant.
URL- CSRF. , , . ( )?
, csrf test.controller.js. , . , , - .
, , .