Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Isomorphic/Universal usage #147

Open
0x4d6165 opened this issue Sep 30, 2016 · 2 comments
Open

Document Isomorphic/Universal usage #147

0x4d6165 opened this issue Sep 30, 2016 · 2 comments

Comments

@0x4d6165
Copy link

I'm still new to Cycle.js so I apologize for my noobiness but how would one go about rendering a Cycle app with cyclic-router by using the req.url (in an express app, for instance)? I can't figure out where to pass the req.url string into the makeRouterDriver function in order to make Cycle render the correct page of my app. Thanks!

@TylorS TylorS changed the title Using cyclic-router in an isomorphic cycle app Document Isomorphic/Universal usage Sep 30, 2016
@TylorS
Copy link
Member

TylorS commented Sep 30, 2016

Hi @gigavinyl, definitely not you, it's just not documented yet. Before I get to that I'll give you a quick idea of

import { makeRouterDriver } from 'cyclic-router'
import switchPath from 'switch-path'
import { createServerHistory } from '@cycle/history'

http.createServer((req, res) => { 
  // call run like usual
  const dispose = Cycle.run(main, {
    DOM: makeHTMLDriver(html => {
      res.end(html) // send out your rendered HTML
      dispose() // clean up resources to prevent memory leaks
    })
    router: makeRouterDriver(createServerHistory(req.url), switchPath)
  })
})

@wyqydsyq
Copy link

wyqydsyq commented Mar 1, 2017

This no longer works with the latest @cycle/history (5.0.0) because that uses the latest history (4.5.x) library underneath which has a different API compared to 3.x.x that cyclic-router is designed against.

I think cyclic-router needs to be changed to either take a Cycle history driver (so we can just pass it a makeHistoryDriver() or makeServerHistoryDriver() from @cycle/history, I imagine this would also remove history as a peer dependency?) or be updated to accept history objects from the latest version of history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants