简体   繁体   中英

Is there a way to access Node.js before it passes over control to Meteor.js in order to serve a static site for some requests?

I want a static website to be served from my-example-domain.com when a user loads a few specific routes.

For example, when loading:

  • /
  • /about
  • /services

But I want different routes to load data from a Meteor application when they're accessed:

For example, when loading:

  • login
  • /dashboard
  • /private-messages

I thought a good way of doing this would be to bypass Meteor's default setup and serve the static site with plain old Node.js if that was possible to hack together. And then, when the user goes to a different route, pass control off to Meteor.

Does anyone know if this would be a legitimate solution to this problem? Or if having the different sites on different subdomains might be better?

Yes, you could intercept request by using webApp.connectHandlers on server side (perhaps in index.js file in your startup/server folder) to use low level res object to serve static content with res.write.

https://docs.meteor.com/packages/webapp.html

You may have to use node fs.readFile to read static html from path as input to res.write.

Having said that I do not know see a good reason to do this. Simply use router such as react-router to control routing for all paths whether static or dynamic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM