-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
271 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,7 @@ | ||
// @ts-check | ||
const fs = require('fs'); | ||
const bodyParser = require('body-parser'); | ||
const path = require('path'); | ||
const express = require('express'); | ||
|
||
const {hydrogenMiddleware} = require('@shopify/hydrogen/middleware'); | ||
|
||
const resolve = (p) => path.resolve(__dirname, p); | ||
|
||
async function createServer() { | ||
const indexProd = fs.readFileSync(resolve('dist/client/index.html'), 'utf-8'); | ||
|
||
const app = express(); | ||
|
||
app.use(require('compression')()); | ||
app.use( | ||
require('serve-static')(resolve('dist/client'), { | ||
index: false, | ||
}), | ||
); | ||
|
||
app.use('*', bodyParser.raw({type: '*/*'})); | ||
|
||
app.use( | ||
'*', | ||
hydrogenMiddleware({ | ||
getServerEntrypoint: () => | ||
require('./dist/server/entry-server.js').default, | ||
indexTemplate: indexProd, | ||
}), | ||
); | ||
|
||
return {app}; | ||
} | ||
const {createServer} = require('./dist/server'); | ||
|
||
createServer().then(({app}) => { | ||
const port = process.env.PORT || 8080; | ||
app.listen(port, () => { | ||
console.log(`Hydrogen running at http://localhost:${port}`); | ||
app.listen(8080, () => { | ||
console.log(`Server ready`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export default { | ||
storeDomain: 'hydrogen-preview.myshopify.com', | ||
storefrontToken: '3b580e70970c4528da70c98e097c2fa0', | ||
storefrontApiVersion: 'unstable', | ||
storefrontApiVersion: '2022-01', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
import {HelmetProvider} from '@shopify/hydrogen/client'; | ||
import CartProvider from './components/CartProvider.client'; | ||
|
||
/** | ||
* Setup client context, though the children are most likely server components | ||
*/ | ||
export default function ClientApp({helmetContext, children}) { | ||
return ( | ||
<HelmetProvider context={helmetContext}> | ||
<CartProvider>{children}</CartProvider> | ||
</HelmetProvider> | ||
); | ||
export default function ClientApp({children}) { | ||
return <CartProvider>{children}</CartProvider>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
import {DefaultRoutes} from '@shopify/hydrogen'; | ||
import renderHydrogen from '@shopify/hydrogen/entry-server'; | ||
import {DefaultRoutes, ShopifyProvider} from '@shopify/hydrogen'; | ||
import {Suspense} from 'react'; | ||
import shopifyConfig from '../shopify.config'; | ||
|
||
import DefaultSeo from './components/DefaultSeo.server'; | ||
import NotFound from './components/NotFound.server'; | ||
import AppClient from './App.client'; | ||
import LoadingFallback from './components/LoadingFallback'; | ||
|
||
export default function App({log, pages, ...serverState}) { | ||
function App({log, pages, ...serverState}) { | ||
return ( | ||
<Suspense fallback={<LoadingFallback />}> | ||
<AppClient helmetContext={serverState.helmetContext}> | ||
<DefaultSeo /> | ||
<DefaultRoutes | ||
pages={pages} | ||
serverState={serverState} | ||
log={log} | ||
fallback={<NotFound />} | ||
/> | ||
</AppClient> | ||
<ShopifyProvider shopifyConfig={shopifyConfig}> | ||
<AppClient> | ||
<DefaultSeo /> | ||
<DefaultRoutes | ||
pages={pages} | ||
serverState={serverState} | ||
log={log} | ||
fallback={<NotFound />} | ||
/> | ||
</AppClient> | ||
</ShopifyProvider> | ||
</Suspense> | ||
); | ||
} | ||
|
||
const pages = import.meta.globEager('./pages/**/*.server.[jt](s|sx)'); | ||
export default renderHydrogen(App, {pages}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.