eddev 0.2.2 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/serverless/create-next-app.js +3 -6
- package/components/BrowserRouter.js +4 -2
- package/package.json +1 -1
- package/routing/remoteProps.d.ts +2 -0
- package/routing/remoteProps.js +7 -0
- package/serverless-template/_utils/fetch-wordpress-props.ts +11 -1
- package/serverless-template/pages/[...slug].tsx +8 -0
|
@@ -126,14 +126,11 @@ function createNextApp(opts) {
|
|
|
126
126
|
"components/**/*",
|
|
127
127
|
"hooks/**/*",
|
|
128
128
|
"queries/**/*",
|
|
129
|
-
".env",
|
|
130
129
|
"views/**/*",
|
|
131
|
-
"theme.css.tsx",
|
|
132
|
-
"types.graphql.ts",
|
|
133
|
-
"types.views.ts",
|
|
134
|
-
"types.blocks.ts",
|
|
135
|
-
"types.api.ts",
|
|
136
130
|
"utils/**/*",
|
|
131
|
+
".env",
|
|
132
|
+
"*.ts",
|
|
133
|
+
"*.tsx",
|
|
137
134
|
"ed.config.json",
|
|
138
135
|
])
|
|
139
136
|
// Also sync APIs into the APIs folder
|
|
@@ -68,11 +68,13 @@ function BrowserRouter(props) {
|
|
|
68
68
|
setIsLoading(true);
|
|
69
69
|
}
|
|
70
70
|
(0, remoteProps_1.fetchProps)(pending.url).then(function (data) {
|
|
71
|
+
console.log("FETCHED", data);
|
|
71
72
|
var view = views_1.default[data.view];
|
|
73
|
+
var nextUrl = data.canonical || pending.url;
|
|
72
74
|
var finish = function () {
|
|
73
75
|
var _a, _b;
|
|
74
76
|
setState({
|
|
75
|
-
url:
|
|
77
|
+
url: nextUrl,
|
|
76
78
|
data: data,
|
|
77
79
|
});
|
|
78
80
|
// setData(data)
|
|
@@ -86,7 +88,7 @@ function BrowserRouter(props) {
|
|
|
86
88
|
setIsLoading(false);
|
|
87
89
|
if (!pending.popped) {
|
|
88
90
|
history.replaceState({ scrollPosition: (_b = document.scrollingElement) === null || _b === void 0 ? void 0 : _b.scrollTop }, "", document.location.href);
|
|
89
|
-
history.pushState({}, "",
|
|
91
|
+
history.pushState({}, "", nextUrl);
|
|
90
92
|
}
|
|
91
93
|
};
|
|
92
94
|
if (view && view.preload) {
|
package/package.json
CHANGED
package/routing/remoteProps.d.ts
CHANGED
package/routing/remoteProps.js
CHANGED
|
@@ -78,6 +78,13 @@ function fetchProps(url) {
|
|
|
78
78
|
promise = fetch(requestUrl)
|
|
79
79
|
.then(function (response) { return response.json(); })
|
|
80
80
|
.then(function (data) {
|
|
81
|
+
if (data.redirect) {
|
|
82
|
+
var redirect_1 = data.redirect;
|
|
83
|
+
return fetchProps(redirect_1).then(function (data) {
|
|
84
|
+
data.canonical = redirect_1;
|
|
85
|
+
return data;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
81
88
|
delete pending[cacheKey];
|
|
82
89
|
cache[cacheKey] = data;
|
|
83
90
|
return data;
|
|
@@ -42,8 +42,18 @@ export async function fetchWordpressProps(pathname: string) {
|
|
|
42
42
|
return url
|
|
43
43
|
})
|
|
44
44
|
|
|
45
|
+
const payload = JSON.parse(text)
|
|
46
|
+
|
|
47
|
+
if (payload.redirect) {
|
|
48
|
+
return {
|
|
49
|
+
status: payload.code,
|
|
50
|
+
redirect: true,
|
|
51
|
+
uri: payload.redirect,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
return {
|
|
46
56
|
status: response.status,
|
|
47
|
-
data:
|
|
57
|
+
data: payload,
|
|
48
58
|
}
|
|
49
59
|
}
|
|
@@ -14,10 +14,18 @@ export async function getStaticPaths(): Promise<GetStaticPathsResult> {
|
|
|
14
14
|
|
|
15
15
|
export async function getStaticProps({ params }: GetStaticPropsContext): Promise<GetStaticPropsResult<any>> {
|
|
16
16
|
const result = await fetchWordpressProps((params?.slug as string[]).join("/"))
|
|
17
|
+
console.log("RESULT", result)
|
|
17
18
|
if (result.status === 404) {
|
|
18
19
|
return {
|
|
19
20
|
notFound: true,
|
|
20
21
|
}
|
|
22
|
+
} else if (result.redirect) {
|
|
23
|
+
return {
|
|
24
|
+
redirect: {
|
|
25
|
+
destination: result.uri,
|
|
26
|
+
permanent: result.status === 301,
|
|
27
|
+
},
|
|
28
|
+
}
|
|
21
29
|
}
|
|
22
30
|
return {
|
|
23
31
|
props: result.data,
|