Skip to content

Commit

Permalink
fix(maleo-core/server): change originalurl to url (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinkl committed Aug 6, 2019
1 parent 39227d0 commit 41e8ee1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions example/playground/routes.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
[
{
"path": "/",
"page": "./src/Root",
"exact": true
},
{
"path": "/search",
"page": "./src/Search",
Expand All @@ -19,5 +14,10 @@
"path": "/detail",
"page": "./src/Detail",
"exact": true
},

{
"path": "/",
"page": "./src/Root",
}
]
2 changes: 1 addition & 1 deletion packages/Maleo.js/src/build/static/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const buildStatic = async (staticPages: StaticPages, dir: string) => {

Object.keys(staticPages).map(async (p) => {
// @ts-ignore
const html = await render({ req: { originalUrl: p }, res: {}, renderStatic: true });
const html = await render({ req: { url: p }, res: {}, renderStatic: true });
const pageName: string = p.replace(/\/?(\/*)(.+)/, '$2');
const pathStaticDir = path.resolve(cwd, STATIC_BUILD_DIR, `${pageName}.html`);

Expand Down
8 changes: 4 additions & 4 deletions packages/Maleo.js/src/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export const render = async ({
const { document: Document, routes, wrap: Wrap, app: App } = await getServerAssets();

// matching routes
const matchedRoutes = await matchingRoutes(routes, req.originalUrl);
const matchedRoutes = await matchingRoutes(routes, req.url);

if (!matchedRoutes.length) {
res.status(404);
return;
}

// get Wrap props & App props
const matched = await getMatchedRoutes(routes, req.originalUrl, matchedRoutes);
const matched = await getMatchedRoutes(routes, req.url, matchedRoutes);
const ctx = { req, res, routes, [MATCHED_ROUTES_KEY]: matched };
const wrapProps = await loadComponentProps(Wrap, ctx);
const { _global_ = {} } = wrapProps || {};
Expand All @@ -80,7 +80,7 @@ export const render = async ({
if (match.path === '**') {
res.status(404);
} else if (branch && route.redirectTo && match.path) {
res.redirect(301, req.originalUrl.replace(match.path, route.redirectTo));
res.redirect(301, req.url.replace(match.path, route.redirectTo));
return;
}

Expand Down Expand Up @@ -198,7 +198,7 @@ export const defaultRenderPage = ({

// in SSR, we need to manually define location object
// to be passed in App because withRouter doesn't work on server side
const location = req.originalUrl;
const location = req.url;

// Head provider
const { HeadProvider, getHeads } = getHeadProvider();
Expand Down

0 comments on commit 41e8ee1

Please sign in to comment.