Hi all we’re switching our Blaze app to React, and want to use react router in lieu of Iron Router. The issue is that the site depends on iron router for server requests, and the two do not play nice. Iron Router hijacks the client routes away from React Router, even though none are configured for Iron Router. We need Iron Router to live on the server, and React Router to live on the client, how do we keep them there?
I know you are using React. But no matter what front end you are using, the Meteor server side is actually same.
The demo Angular2-Universal-Meteor is not for React specific, but it may help you.
It uses Angular router on client side, and FlowRouter on the server side.
Iron Router can do server side routing and this is why I decided to develop my rest API with it. I could also make the client side routing with Iron Router, but this is not possible when using React (it only supports Blaze)…
I’m sure there is a way to disable Iron Router on client side to use another router such as Flow Router or React Router. I tried this, but it doesn’t work.
I’m gonna try to use both Iron Router and Flow Router together.
Thanks @robfallows.
Yes I did try restivus, and I was not able to upload and parse files with busboy.
If I’m not wrong, simple:rest doesn’t handle server side file upload.
I will try centiq:crud
@thomaskn thanks for investigating. I came across the same issue. Did you figure it out?
Yea, Flow and React routes are both client side only so no way to use FlowRoute on server.
Thanks
I do server-side uploads with this all the time and it works great. I’ve only had good experiences with AWS’s sdk. I wouldn’t recommend using more than one router at the same time.
Then I configured the notFoundTemplate in route.js:
if (Meteor.isClient) {
Router.configure({
notFoundTemplate: 'pageNotFound',
});
}
So each time a page is loaded the iron:router splash screen is empty: <div id="notFound"></div>
But this is just a way to hide the splash screen, I didn’t find a solution to deactivate iron:router on client side.
@streemo thanks for your help! I decided to use iron:router to build a REST API. It works amazingly well but I just want it to work on server side. Using the meteor-aws-sdk will not help me building the REST API. Do you know a meteor package to build a REST API that can handle server side file upload?
I use cfs:standard-packages to deal with file upload and iron:router to build the REST API.
Which package do you use for your REST endpoints? I’ll give meteor hacks:picker a try.
I used Iron Router before for both Client and Server side routing. After migrating off of IR and onto FlowRouter (and I’m soon going to move onto my version of FlowRouter named FineRouter after seeing 9 PRs on FlowRouter unanswered), I needed a server side router to fill in as FlowRouter is client side only. Picker worked great. I also made a version of Picker called FinePicker by the way. Anyone that wants to add PRs or contribute to FineRouter or FinePicker is more than welcomed.
Might not be that relevant or overly complex, but I implement these kinda things by just starting an express server in parallel. You just install express and get-ports (to find a free port) with npm.
You start the express server on a free port and store that port in a global variable. On the client you can call a method that gets the url for the express server from the meteor server. Works very well for my specific needs, so might be an option for others.
IIRC Collection FS has been deprecated and is no longer maintained. I highly recommend using picker and then doing this:
//approximately
import AWS from "peer-library:aws-sdk"
let S3 = new AWS.S3()
Picker.route('/api/v1/upload/',(req,par,res,next)=>{
if (!passSecurityTest(req)){
return res.end(403)
}
const opts = getOptsFromParams(par);
S3.uploadFileSync(opts); //uploads to your s3 bucket.
}
It’s very straightforward. There are also known problems with uploading large files over ddp, where the socket interrupts after a few megabytes of piped data. I’m not sure if that’s still a problem or was fixed. None of what I am saying is useful for you if you absolutely must store objects in your own database. S3 is a great external storage for files, and is pretty easy to use.