Comments (5)
Hey @mimiz,
I believe frontend (react bits) and the backend (api) should be decoupled. React is the hot thing today but tomorrow we can all move onto the next hot thing in the market. API's are supposed to be independent of that.
Decoupling also allows you to use another language/framework in the future with your API too, if you so choose.
You have a few options for code sharing though:
-
Build a package (NPM): You can put all of the common utility code inside an NPM library. Keep in mind you can "install" libraries outside of NPM, via Git, HTTP or from local directories. This also allows you version your code, but that's a double edged sword since you would, in theory, need to keep pushing new versions for most of your edits.
-
Import it directly: You can create a directory structure with 3 main directories:
frontend
,api
andcommon
. In your API or frontend code, call it withrequire('../common')
or the equivalentimport
ES6 syntax. If you use bundling (for example with webpack), this also bundles the common functions inside each application's (api and frontend) own bundle.
Let me know if you have more questions.
Should also point out I'm no longer part of @barbar, so opinions of them may be different from my own.
from vortigern.
You can always proxy the API inside the frontend code, which easily allows you to serve both on the same domain and from the same application. Of course, this all depends on your specific needs.
from vortigern.
https://twitter.com/Todd_McLeod/status/920784947215863808
from vortigern.
Hey, @batuhan,
Thanks a lot for your advice, and I think you are right. Sorry for my late response but I was on holiday AFK!
I will follow your ideas !
Regards
Rémi
from vortigern.
@batuhan what I do is implement my API separately, export a swagger definition file, and then generate a typescript proxy interface which I put in a NPM package. Then I import this API proxy in my react-native code as well as the vortigern-based site.
I actually implemented the API in C# using ASP.NET Web API which worked really well for my backend needs. All the types are initially defined in C# and Typescript versions of the classes are generated through the swagger toolchain.
Resources:
- Swagger: https://swagger.io/
- Swagger-codegen: https://github.com/swagger-api/swagger-codegen
from vortigern.
Related Issues (20)
- CSS sourcemap is missing in dev.config? HOT 2
- Dockerfile HOT 2
- What are the advantages in bundling server side code? HOT 2
- Unable to have redux-form working
- Upgrade to [email protected]
- Stale DOM classnames: changing component classname requires server restart HOT 1
- the problem of a vendor/main.ts loaded after DOM HOT 2
- Test output not showing correct line numbers
- Order of vendor imports HOT 1
- Barbar Startup Factory link is wrong
- Dupe test declarations for .css files in webpack config?
- webpack v4
- Urgently help
- ERROR in [at-loader] ./node_modules/redux-thunk/index.d.ts:14:84 TS2315: Type 'Middleware' is not generic. HOT 1
- is this project still active? HOT 6
- an error occured when run npm start as the img below
- [request] Add scss support
- Can't Generate PWA, can't cache the server generated strings.
- [solved / for-the-record] Typescript errors on `npm run start`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vortigern.