Skip to content

Commit c47213d

Browse files
committed
Part 3 - Convert bootstrap.js into bootstrap.ts
At this point we are going to re-write the bootstrap file in Typescript. Nothing much to add in here, other than the fact that we're now type hinting the elements involved.
1 parent 58f91da commit c47213d

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

resources/js/bootstrap.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

resources/js/bootstrap.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'bootstrap';
2+
import Axios, {AxiosStatic} from 'axios';
3+
4+
declare global {
5+
// Extending the DOM Window Interface
6+
interface Window {
7+
axios: AxiosStatic;
8+
}
9+
10+
// Extending querySelector Element
11+
interface Element {
12+
content: string;
13+
}
14+
}
15+
16+
declare var window: Window;
17+
window.axios = Axios;
18+
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
19+
20+
const token: Element | null = document.head.querySelector('meta[name="csrf-token"]');
21+
22+
if (token) {
23+
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
24+
} else {
25+
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token')
26+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy