Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
feat(app): send x-csrf-token with every post
Browse files Browse the repository at this point in the history
Closes #1103
  • Loading branch information
Christine Yu committed Jul 30, 2015
1 parent 4123893 commit 6508e77
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,26 @@ function appConfig($urlRouterProvider: ng.ui.IUrlRouterProvider,
$locationProvider: ng.ILocationProvider,
RestangularProvider: restangular.IProvider,
config: IGDCConfig,
$compileProvider: ng.ICompileService
$compileProvider: ng.ICompileService,
$httpProvider: ng.IHttpProvider
) {

$compileProvider.debugInfoEnabled(!config.production);
$locationProvider.html5Mode(true);
$urlRouterProvider.otherwise("/projects");
RestangularProvider.setBaseUrl(config.api);
RestangularProvider.setDefaultHttpFields({
cache: true
});

/**
The regex is from https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie in Example #2.
Cookies are stored in document.cookie as "cookieName1=cookieValue; cookieName2=cookieValue"
so the capturing group after the "csrftoken=" captures the value and places it into var csrftoken.
Unable to use $cookies because services can't be injected in config step
**/
var csrftoken = document.cookie.replace(/(?:(?:^|.*;\s*)csrftoken\s*\=\s*([^;]*).*$)|^.*$/, "$1");
$httpProvider.defaults.headers.common['X-Csrf-Token'] = csrftoken;

}

/* @ngInject */
Expand Down

0 comments on commit 6508e77

Please sign in to comment.