You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/tutorial/04-advanced-sveltekit/06-environment-variables/01-env-static-private/README.md
+19-19Lines changed: 19 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -2,22 +2,22 @@
2
2
title: $env/static/private
3
3
---
4
4
5
-
Environment variables — like API keys and database credentials — can be added to a `.env`file, and they will be made available to your application.
5
+
Biến môi trường - như khóa API và thông tin đăng nhập cơ sở dữ liệu - có thể được thêm vào tệp `.env`và sẽ có hiệu lực trong ứng dụng của bạn.
6
6
7
-
> You can also use `.env.local`or`.env.[mode]`files — see the [Vite documentation](https://vitejs.dev/guide/env-and-mode.html#env-files)for more information. Make sure you add any files containing sensitive information to your `.gitignore`file!
7
+
> Bạn cũng có thể sử dụng các tệp `.env.local`hoặc`.env.[mode]`- xem [tài liệu Vite](https://vitejs.dev/guide/env-and-mode.html#env-files)để biết thêm thông tin. Hãy nhớ thêm bất kỳ tệp nào chứa thông tin nhạy cảm vào `.gitignore`của bạn!
8
8
>
9
-
> Environment variables in `process.env`are also available via`$env/static/private`.
9
+
> Biến môi trường trong `process.env`cũng có sẵn qua`$env/static/private`.
10
10
11
-
In this exercise, we want to allow the user to enter the website if they know the correct passphrase, using an environment variable.
11
+
Trong bài tập này, bằng cách sử dụng biến môi trường, chúng ta muốn cho phép người dùng truy cập trang web nếu họ biết passphrase đúng.
12
12
13
-
First, in`.env`, add a new environment variable:
13
+
Đầu tiên, trong`.env`, thêm một biến môi trường mới:
14
14
15
15
```env
16
16
/// file: .env
17
17
PASSPHRASE=+++"open sesame"+++
18
18
```
19
19
20
-
Open`src/routes/+page.server.js`. Import `PASSPHRASE`from`$env/static/private`and use it inside the[form action](/tutorial/the-form-element):
20
+
Mở`src/routes/+page.server.js`. Import `PASSPHRASE`từ`$env/static/private`và sử dụng nó bên trong[form action](/tutorial/the-form-element):
21
21
22
22
```js
23
23
/// file: src/routes/+page.server.js
@@ -49,13 +49,13 @@ export const actions = {
49
49
};
50
50
```
51
51
52
-
The website is now accessible to anyone who knows the correct passphrase.
52
+
Trang web giờ có thể truy cập cho bất kỳ ai biết passphrase đúng.
53
53
54
-
## Keeping secrets
54
+
## Giữ bí mật
55
55
56
-
It's important that sensitive data doesn't accidentally end up being sent to the browser, where it could easily be stolen by hackers and scoundrels.
56
+
Điều quan trọng là dữ liệu nhạy cảm không vô tình bị gửi tới trình duyệt, nơi nó có thể dễ dàng bị đánh cắp bởi hacker và những kẻ gian.
57
57
58
-
SvelteKit makes it easy to prevent this from happening. Notice what happens if we try to import `PASSPHRASE`into`src/routes/+page.svelte`:
58
+
SvelteKit giúp bạn dễ dàng ngăn chặn điều này xảy ra. Lưu ý điều gì sẽ xảy ra nếu chúng ta thử import `PASSPHRASE`vào`src/routes/+page.svelte`:
59
59
60
60
```svelte
61
61
/// file: src/routes/+page.svelte
@@ -65,28 +65,28 @@ SvelteKit makes it easy to prevent this from happening. Notice what happens if w
65
65
</script>
66
66
```
67
67
68
-
An error overlay pops up, telling us that `$env/static/private`cannot be imported into client-side code. It can only be imported into server modules:
68
+
Một bảng lỗi xuất hiện, thông báo cho chúng ta rằng `$env/static/private`không thể được import vào mã chạy ở phía client. Nó chỉ có thể được import vào các mô-đun server:
69
69
70
70
-`+page.server.js`
71
71
-`+layout.server.js`
72
72
-`+server.js`
73
-
-any modules ending with`.server.js`
74
-
-any modules inside`src/lib/server`
73
+
-bất kỳ mô-đun nào kết thúc bằng`.server.js`
74
+
-bất kỳ mô-đun nào trong`src/lib/server`
75
75
76
-
In turn, these modules can only be imported by _other_server modules.
76
+
Lần lượt, những mô-đun này chỉ có thể được import bởi những mô-đun server _khác_.
77
77
78
-
## Static vs dynamic
78
+
## Tĩnh và động
79
79
80
-
The`static`in`$env/static/private`indicates that these values are known at build time, and can be _statically replaced_. This enables useful optimisations:
80
+
Chữ`static`trong`$env/static/private`chỉ ra rằng những giá trị này được biết tại thời điểm build và có thể được _thay thế tĩnh_. Điều này giúp ích trong việc tối ưu hóa:
//code in here will be removed from the build output
88
-
//if FEATURE_FLAG_X is not enabled
87
+
//mã ở đây sẽ bị xóa khỏi kết quả build
88
+
//nếu FEATURE_FLAG_X không bằng enabled
89
89
}
90
90
```
91
91
92
-
In some cases you might need to refer to environment variables that are _dynamic_ — in other words, not known until we run the app. We'll cover this case in the next exercise.
92
+
Trong một số trường hợp, bạn có thể cần tham chiếu đến các biến môi trường là _động_ - nói cách khác, ta không biết cho đến khi chúng ta chạy ứng dụng. Chúng ta sẽ đề cập đến trường hợp này trong bài tập tiếp theo.
Copy file name to clipboardExpand all lines: content/tutorial/04-advanced-sveltekit/06-environment-variables/01-env-static-private/app-a/src/routes/+page.svelte
Copy file name to clipboardExpand all lines: content/tutorial/04-advanced-sveltekit/06-environment-variables/02-env-dynamic-private/README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: $env/dynamic/private
3
3
---
4
4
5
-
If you need to read the values of environment variables when the app runs, as opposed to when the app is built, you can use `$env/dynamic/private`instead of`$env/static/private`:
5
+
Nếu bạn cần đọc giá trị của biến môi trường khi ứng dụng chạy, thay vì khi ứng dụng được xây dựng, bạn có thể sử dụng `$env/dynamic/private`thay vì`$env/static/private`:
Copy file name to clipboardExpand all lines: content/tutorial/04-advanced-sveltekit/06-environment-variables/04-env-dynamic-public/README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: $env/dynamic/public
3
3
---
4
4
5
-
As with [private environment variables](/tutorial/env-static-private), it's preferable to use static values if possible, but if necessary we can use dynamic values instead:
5
+
Tương tự như [biến môi trường riêng tư](/tutorial/env-static-private), nếu có thể, thì nên sử dụng giá trị tĩnh, nhưng nếu cần thiết, chúng ta cũng có thể sử dụng giá trị động:
0 commit comments