I'm working with Yii Framework 2. How can I create an app with one backend and two front ends?
For example:
Backend for Admins and Moderators (url: admin.example.com)
Frontend app for Publishers (url: publisher.example.com)
Frontend app for Advertisers (url: advertiser.example.com)
All apps should have a common db, models and 3 different layouts.
I found a Yii2 advanced template where are only two: frontend and backend.
You can build as many fronts as you need by adding them as independent modules. Each within a separate folder, with its own configs and own controllers. Then they may all share the same models.
You may check Module docs for more details or you may also check this example which is built for REST on top of a basic template, so you'll need different apache and app configs but it is practically the same.
Related
I'm not sure if what I want is possible, I haven't found anything that says it could be done.
Mostly I "think" it should be possible.
The thing is: I have a seperate file for my api and user interface, and would love to deploy both using zeit-now for now (see file struct below, hope it's clear).
Now the main question is, is it possible to deploy both api.js and server.js using zeit-now?
Kind regards,
Daneel
root
|-api
|--api.js
|-ui
|--server.js
Unless you specify your own custom routes in your now.json file, anything in the root api folder will be treated by Zeit as both serverless functions and the core of your project. Your best bet is to deploy two separate projects within Zeit — your frontend (which should be a static-build JAMstack-style site) and your backend, which is comprised of serverless functions, to which your frontend app makes API calls.
I have angular 6 micro front end application. It's having 4 different applications inside Main application. And how do i implement routing between those applications.And how do i implement routing in Main application (i have many child routes in Main application) and Sub applications too. I am using "#angular/elements".
Please find my code in this this repository https://github.com/nagaraju123/microfrontend
Routing for a "true" microfrontend architecture should follow:
Each microfrontend is a separate service in your infrastructure
You have an ingress/reverse proxy in front of these services that allows routing to a specific service based on path
You have a single domain name: app.yoursite.com
You configure the ingress to route to the correct microfrontend based on path (e.g. /namespace/accounting goes to the accounting frontend)
The microfrontends themselves control how they make requests (e.g. the accounting frontend serves some accountingPage.js, and code within that page will make all fetch requests with prefix: /namespace/accounting)
Summary:
It really depends on what you mean by "microfrontend" though. Often when people say microfrontend, they refer to creating separate JS bundles, but still sharing a single backend.
A "true" microfrontend architecture achieves total encapsulation of both the static assets/javascript and the backend/request handlers. Separation of concerns, not separation of technologies. Code served by one microfrontend is totally isolated from code served by another... stitched together by a common "platform" service.
I am working on a project that requires developing a SPA using React, Node and Express. I understand Node/Express can serve static files and so my initial thought was I will write a react app and serve it via Express server.
But my Node/Express server also has other roles like, connecting with other microservices and fetch data, which will eventually passed to the UI controlled by react SPA.Sort of a controller! I am also planning to use Graphql instead of Rest.
Will the approach of using the Express server to do both serving the SPA and as a controller has any complication, or should I separate them as two different webapps.
I couldn't find many usecases for my first approach (keeping both together),but I could see that splitting them as two,like here https://dev-blog.apollodata.com/full-stack-react-graphql-tutorial-582ac8d24e3b
Any suggestions on what is the right approach?
Thanks
If you just wanna serve a static file you can use Amazon S3 bucket to serve your React app and throw a a CDN in front of it for optimal load times.
Its nice to keep the separated but it also depends on the size and scope of the project. If you wanna expand it later it might hurt that your API is also serving the app and all its assets.
Where as separating them will split the load from actual API usage and static asset requests (images, index.html ect...).
I have been developing JEE web app using Spring Boot and jQuery so far and this is the first time I am developing a NodeJS/ Angular2 app. In JEE application, both client as well as server side component gets compiled into a single jar/ war file. However, in my new development environment, I am developing client and server side as two separate projects (listening to different ports) and calling the backend url from Angular2 service layer. I am having Cross Origin Resource Sharing (CORS) issue.
My question is, is this common practice to develop Angular and NodeJS as two separate application and resolve the CORS issue through using cors module in NodeJS?
I found some solution as below from Node side:
var cors = require('cors')
var app = express()
app.use(cors())
So, I appreciate if you can help me clarify
Right project structure in this architecture
Recommended resolution for the CORS issue.
Regards.
Yes, it is quite common to use two separate projects in for the front- and backend. But this doesn't mean it's the best or only way to do it. It always depends on your specific requirements and the size of your project. For smaller projects it's probably easier to have both projects in the same repository, but this is a personal preference.
Regarding CORS it really depends on what you are trying to do. Just because you have two separate repositories doesn't mean that you have to serve them on different domains/ports. For example, you could use nginx to route the requests to your API or frontend depending on the url. If they are not hosted on the same domain/port you have to disable CORS, as you said. Try to make the rules as strict as possible and only allow your specific domain.
I am interested in creating a CRUD Rest API using Node.js together with express. I was wondering if their was a structuring standard of some sort or MVC framework which is used in the industry to structure my code create models etc...
I know that I should structure the different models into different npm projects but how to structure a single project is what I am looking for...
Also I am very interested in using a mediator design pattern to decrease coupling between the different modules.
Any examples/blogs/gits/books will help
Thanks
I did a screencast on this topic in which I propose an app structure that has served me well for APIs and projects with UIs. Do I claim this is gospel and then end-all-be-all? No. But it has served me well.
In short it looks something like this:
app_root
app
routes
- route handlers go here
models
- if you use models
commands
- if you use commands
middleware
- middlewarez
config
application.js - the stuff that bootstraps your application. Reusable in contexts other than your server (thing testing)
routes.js - All your route mappings in one place
test
test_helper.js - Bootstrap your testing (require config/application.js, etc)
models
- tests for your models (follow suit for other things under app)
server.js - starts up your webserver
I put this empty app structure up on GitHub here.
You could use Google's AngularJS + Node.JS where the angular frameworkwork separates view and controller. Look into Angular site for example and tutorial.