-
Notifications
You must be signed in to change notification settings - Fork 688
/
Copy pathupward.yml
258 lines (243 loc) · 7.86 KB
/
upward.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# This is a top-level object used to set values for the root `status`,
# `headers`, and `body` properties.
# It is the first branch in an abstract decision tree, which ultimately
# resolves to an object that contains values for its own 'status', 'headers',
# and 'body' properties.
# This object uses a ConditionalResolver to determine the object value based
# on the URL pattern in the request object.
veniaResponse:
resolver: conditional
when:
# Requests to graphql/rest endpoints, the media library, and cache are
# handled by the top-level 'veniaProxy' object, which is a ProxyResolver
# that passes the request through to the backing Magento server.
- matches: request.url.pathname
pattern: '^/(graphql|rest|media)(/|$)'
use: veniaProxy
- matches: request.url.pathname
pattern: '^/(robots\.txt|favicon\.ico|manifest\.json)'
use: staticFromRoot
- matches: fileExtension
pattern: '(js|json|png|jpg|gif|svg|ico|css|txt)'
use: veniaStatic
- matches: urlResolver.redirect_code
pattern: '(301|302)'
use: dynamicRedirect
default: veniaAppShell
# A FileResolver for serving certain files directly from document root,
# even though they are published to the `static` folder in build assets.
staticFromRoot:
inline:
status: 200
headers:
resolver: inline
inline:
content-type: contentTypeFromExtension
cache-control:
when:
- matches: env.NODE_ENV
pattern: 'production'
use:
inline: public, max-age=604800
default:
inline: no-cache, no-store, must-revalidate
body:
resolver: file
parse:
inline: text
encoding:
inline: binary
file:
resolver: template
engine: mustache
provide:
filename: request.url.pathname
template:
resolver: inline
inline: './venia-static/{{ filename }}'
contentTypeFromExtension:
when:
- matches: fileExtension
pattern: '^ico$'
use:
inline: image/x-icon
- matches: fileExtension
pattern: '^txt$'
use:
inline: text/plain
- matches: fileExtension
pattern: '^json$'
use:
inline: application/json
default:
inline: text/html
# Contains the file extension--the part after the dot--of the URL path.
fileExtension:
resolver: conditional
when:
- matches: request.url.pathname
pattern: '\.(.*)$'
use: $match.$1
default:
inline: ''
# A ProxyResolver object that passes a request to the backend Magento
# server defined in the MAGENTO_BACKEND_URL environment variable.
# An UPWARD server infers this object as a ProxyResolver due to the presence
# of the 'target' property.
veniaProxy:
resolver: proxy
target: env.MAGENTO_BACKEND_URL
# A local Magento install may have SSH configured and untrusted,
# which is not a major concern for this one origin, especially if
# containerized. Clients which require trust may proxy through UPWARD.
ignoreSSLErrors:
when:
- matches: env.NODE_ENV
pattern: 'production'
use:
inline: false
default:
inline: true
# Page type data for initial render
veniaPageType:
resolver: inline
inline:
data:
resolver: computed
type:
resolver: inline
inline: pageType
additional:
- type: product
fetch: '__typename,id'
- type: cms_page
fetch: 'identifier'
- type: category
fetch: 'uid'
# Nonce for page type inline script
veniaPageTypeNonce:
resolver: inline
inline:
nonce:
resolver: computed
type:
resolver: inline
inline: pageTypeNonce
# Webpack chunks to preload on page based on page type
veniaWebpackChunks:
resolver: inline
inline:
scripts:
resolver: computed
type:
resolver: inline
inline: webpackChunks
# The veniaAppShell object resolves to a response that returns server-side
# rendered HTML containing the PWA application shell.
# For SEO purposes, the appropriate meta tags in the HTML head element are also
# set based on information about the resource.
# This object uses properties in the top-level 'veniaResponse' object to return
# the appropriate response values.
veniaAppShell:
resolver: inline
inline:
status:
resolver: inline
inline: 200
headers:
resolver: inline
inline:
content-type:
inline: text/html
cache-control:
inline: s-maxage=60
body:
resolver: template
engine: mustache
provide:
pageType: veniaPageType.data
pageTypeNonce: veniaPageTypeNonce.nonce
webpackChunks: veniaWebpackChunks.scripts
template:
resolver: file
file:
resolver: inline
inline: './index.html'
# The veniaStatic object is a DirectoryResolver that allows access to the files
# inside the project's compiled './dist' directory.
veniaStatic:
resolver: directory
directory:
resolver: inline
inline: '.'
# These are no-ops at runtime; nothing refers to these context values in the
# rest of this file. They exist to declare that the files in the `./static`
# directory are required and should be copied into the build assets by the
# UpwardIncludePlugin. Since they are not directly mentioned elsewhere in this
# file or any other upward.yml file in the build, the UpwardIncludePlugin would
# fail to copy them if they were not mentioned here.
# The static directory includes files which don't need to be compiled.
# They are served by the `veniaStatic` DirectoryResolver, along with the
# bundles and other assets, but since that resolver serves the `.` dist
# directory, the UpwardIncludePlugin will not copy it to avoid circular
# dependency. TODO: This is kind of confusing.
veniaStaticIncludes:
resolver: directory
directory:
resolver: inline
inline: './venia-static'
urlResolver: urlResolverResult.data.route
urlResolverResult:
resolver: service
endpoint:
resolver: url
baseUrl: env.MAGENTO_BACKEND_URL
pathname:
inline: graphql
method:
resolver: inline
inline: POST
headers:
resolver: inline
inline:
'content-type': 'application/json'
accept: 'application/json'
query:
resolver: inline
inline: 'query ResolveURL($url: String!) {
route(url: $url) {
type
relative_url
redirect_code
}
}'
variables:
resolver: inline
inline:
# This is a barestring indicating a context lookup. It resolves to the
# `path` value in the URL query string of the request, using the builtin
# `request` context object.
url: request.url.pathname
dynamicRedirect:
resolver: inline
inline:
status: urlResolver.redirect_code
headers:
resolver: inline
inline:
content-type:
inline: text/html
cache-control:
inline: s-maxage=60
body:
resolver: template
engine: mustache
provide:
pageType: veniaPageType.data
pageTypeNonce: veniaPageTypeNonce.nonce
webpackChunks: veniaWebpackChunks.scripts
template:
resolver: file
file:
resolver: inline
inline: './index.html'