example implementation for server side rendering?
See original GitHub issueHi! First, thanks for your tremendously awesome work on this ecosystem. I’ve been using next.js for two days now and for the most part everything just works. Very impressive given all the complexity under the hood!
I have one question… are there any examples of using styled-jsx with a custom server? I see you have a request handler in the readme, but I’m not sure how to wire that up to this:
const micro = require('micro')
const match = require('micro-route/match')
const { parse } = require('url')
const next = require('next')
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const server = micro(async (req, res) => {
const parsedUrl = parse(req.url, true)
const { query } = parsedUrl
if (match(req, '/a')) {
return app.render(req, res, '/b', query)
} else if (match(req, '/b')) {
return app.render(req, res, '/a', query)
}
return handle(req, res, parsedUrl)
})
app.prepare().then(() => {
server.listen(port, err => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}`)
})
})
I’d be happy to contribute back some documentation around this (or a PR example to the next.js repo) if you could help clarify this for me.
Cheers!
Issue Analytics
- State:
- Created 6 years ago
- Comments:11
Top Results From Across the Web
How to implement server-side rendering in your React app in ...
In this tutorial, we'll use server-side rendering to deliver an HTML response when a user or crawler hits a page URL.
Read more >Server-Side Rendering in React using Next.js
Server-side rendering with JavaScript libraries like React is where the server returns a ready-to-render HTML page and the JS scripts required ...
Read more >How to Enable Server-Side Rendering for a React App
First, use npx to start up a new React app using the latest version of Create React App. Let's call the app, react-ssr-example...
Read more >Basics of React server-side rendering with Express.js
We're going to go through a simple, but limited, implementation of server-side rendering just to get you an idea on how it works....
Read more >A beginner's guide to React Server-Side Rendering (SSR)
Whenever a user clicks on a link, instead of sending a new request to the server for HTML of that page, we create...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sure can. Ack. I should have started with an isolated test case. Apologies for the wasted time.
For clarity sake, the reason I asked the question to begin with was because of this line in the README:
To my mind that says I need to do something to get SSR rolling for styled-jsx.
I’ll break it down to something small and reproducible (and probably figure out the issue on my own in doing so) later today. Will follow up with my results soon!
Closing this. Happy to reopen in case you need help again 😃