-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathupward.yml
213 lines (200 loc) · 7.82 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
# This is the UPWARD specification file for the Venia storefront.
# It is used by an UPWARD server implementation, such as upward-js and
# upward-php, to describe how the server responds to requests.
# See: https://pwastudio.io/technologies/upward/
# The root properties of an UPWARD spec file are part of a global context
# that includes request and environment data.
# These properties are available to other properties and are ultimately
# populated with Resolvers.
# The root 'status', 'headers', and 'body' properties are required properties
# in an UPWARD spec file.
# An UPWARD server uses the resolved values of these properties to create an
# HTTP response to the client.
# In this file, these properties get their values from a top-level
# 'response' object, which is a recommended and best practice approach.
status: siminiaResponse.status
headers: siminiaResponse.headers
body: siminiaResponse.body
# 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.
siminiaResponse:
resolver: conditional
when:
# Requests to graphql/rest endpoints, the media library, and cache are
# handled by the top-level 'siminiaProxy' object, which is a ProxyResolver
# that passes the request through to the backing Magento server.
- matches: request.url.pathname
pattern: '^/(graphql|rest|media|pub)(/|$)'
use: siminiaProxy
- matches: request.url.pathname
pattern: '^/(robots\.txt|favicon\.ico|manifest\.json)'
use: staticFromRoot
#url resize added back
- matches: request.url.pathname
pattern: '^/img/resize/(\d+)'
use: imageOpt
- matches: fileExtension
pattern: '(js|json|png|svg|ico|css|txt|ttf|woff2|otf|gif)'
use: siminiaStatic
#param contain simiforceproxy would use proxy directly to magento site
- matches: request.url.search
pattern: 'simiforceproxy'
use: siminiaProxy
#path contain simiforceproxy would use proxy directly to magento site
- matches: request.url.pathname
pattern: 'simiforceproxy'
use: siminiaProxy
default: siminiaAppShell
# 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
body:
resolver: file
parse:
inline: text
file:
resolver: template
engine: mustache
provide:
filename: request.url.pathname
template:
resolver: inline
inline: './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.
siminiaProxy:
resolver: proxy
target: env.MAGENTO_BACKEND_URL
# A local Magento install may have SSH configured and untrusted,
# which is not a major concern, especially if containerized.
ignoreSSLErrors:
resolver: inline
inline: true
# The siminiaAppShell 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 'siminiaResponse' object to return
# the appropriate response values.
siminiaAppShell:
resolver: inline
inline:
status:
resolver: inline
inline: 200
headers:
resolver: inline
inline:
content-type:
inline: text/html
body:
resolver: file
file:
resolver: inline
inline: './index.html'
# The siminiaStatic object is a DirectoryResolver that allows access to the files
# inside the project's compiled './dist' directory.
siminiaStatic:
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 `./templates`
# and `./static` directories 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 templates directory includes partials which are only required by other
# templates, and the UpwardIncludePlugin cannot parse templates to see them.
siminiaTemplateIncludes:
resolver: directory
directory:
resolver: inline
inline: './templates'
# The static directory includes files which don't need to be compiled.
# They are served by the `siminiaStatic` 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.
siminiaStaticIncludes:
resolver: directory
directory:
resolver: inline
inline: './static'
# The imageOpt object returns an HTTP redirect response (301) to Fastly, an
# image optimization service.
#
# This is mainly used in production mode when the PWA does NOT have a
# Fastly-specific URL factory.
# This object forwards to Fastly where it is present, and drops back to the
# uncompressed image otherwise.
# If this application runs on a non-FastlyIO server, an onboard resizing service
# is highly recommended.
#
# NOTE: In dev and staging mode, the PWADevServer and Venia's server.js declare
# the image resizing middleware at `/img/` before the UpwardPlugin declares
# middleware, so a request should never get here.
#
# In production mode when USE_FASTLY is true, the Venia PWA has a
# Fastly-specific URL factory. It should also never hit this route.
imageOpt:
inline:
status: 301
body:
inline: ''
headers:
inline:
Location:
# A UrlResolver is used to generate the URL location
# uncomment configuration below to switch to upward host instead of
# magento host to run image resize when Magento and PWA
# are from different domains (width param only work with upward)
#baseUrl: request.headers.host
baseUrl: env.MAGENTO_BACKEND_URL
pathname: request.url.query.url
query:
inline:
auto:
inline: webp
format:
inline: pjpg
width: $match.$1