Coder Social home page Coder Social logo

Comments (12)

nilslice avatar nilslice commented on April 28, 2024 2

@krismeister is right, as a REST-like service, Ponzu should just be accessed as a HTTP interface to your data which you interact with from different clients (web app, iOS app, smart TV, another service, CLI, etc).

Sometimes though you just have a little project or a small business client that anything beyond a single server is overkill. That's what I would be designing the "frontend" addon to address. Essentially it would consist of Assets (for uploading static content, like css/js/img/etc) and Pages which have runtime defined routes, ("Home" -> "/", "About" -> "/about", etc). Each page would get a context, which is mapped to an API endpoint that you would enter: "/api/contents?type=About&count=1". Each page would also get a *template.Template editable in a textarea, but also possibly mapped to a file in a special directory (which would be overwritten if edited in the CMS UI). In addition to the Assets and Pages types, there would likely need to be a Partials type which would consist of just named *template.Template's to use as included templates like header, footer, sidebar etc..

Once you add a page, with its route, context and template, it is rendered as follows:

  • route is requested
  • context API call is made, getting data from the DB
  • template is executed with the data from the context
  • []byte from template is written to the response

I suppose there could also be data passed to the template including the req.Form to be able to read and use values in the URL or request

It would be an Addon since, like @krismeister mentions, Ponzu is focused on being a great CMS and server, but not concerned with rendering views. However, I see the benefit of providing this as an option to users and know I would personally benefit from having a quick way to deploy a single system and have it do both server & client for smaller projects.

@martinsotirov - would that be something that you'd consider using? For a JS web app, you would just register a "/" route and all others would match it, rendering the "bootstrap" page that sets up a view and client-side router for your JS to take over.

from ponzu.

martinsotirov avatar martinsotirov commented on April 28, 2024 1

@nilslice yeah, that does sound like a useful addon. Something like that could cover a large part of my smaller client projects that I know do with WordPress.

from ponzu.

nilslice avatar nilslice commented on April 28, 2024

You can add any handlers you want just by registering them to the default serve mux anywhere in your content files or better yet by creating and enabling an addon.

the quickest way would just be to add a handler like this:

// in content/yourtype.go
// add to the init() func:

http.HandleFunc("/app", seoHandler)

when you re build and run (without changing the api,admin services) you should see that handler working.

I'd love to see your solution if you plan to make it open (or partially open) source. You could make this more extensible by creating an addon.. see examples here: https://github.com/ponzu-cms/addons - you can create an addon that could be enabled/disabled and have some UI within the CMS (like FB Scheduler, or something that is just a vendored package like Reference).

Let me know if you have questions or need any additional direction.

from ponzu.

nilslice avatar nilslice commented on April 28, 2024

You can see all of the routes pre-registered within the following files:

system/admin/server.go
system/api/server.go

(I'm on mobile at the moment so I apologize if those aren't precise)

The main point is even the '/' route has been left open so you could do whatever you'd like with it.

from ponzu.

martinsotirov avatar martinsotirov commented on April 28, 2024

I see. Thanks :)

I'll try the addon approach.

from ponzu.

nilslice avatar nilslice commented on April 28, 2024

Sounds good. Please let me know how it goes -- there isn't any documentation for addons, so you're kind of exploring new territory. I am happy to help.

Report back how it goes if you don't mind. I need some feedback on addons before I do all the docs. You're probably one of the first Ponzu users to make an addon aside from me.

from ponzu.

nilslice avatar nilslice commented on April 28, 2024

Hi @martinsotirov -

Were you able to achieve your desired outcome using Ponzu? I am interested in making a "frontend" addon of sorts and thought you might have thoughts if you ended up going forward with an addon of your own.

Thanks!

from ponzu.

martinsotirov avatar martinsotirov commented on April 28, 2024

Hey @nilslice , I couldn't really achieve exactly what I wanted – render Vue.js server side with Go alone, because the Vue.js server side renderer seems to have some hard Node.js dependencies.

In the end I managed to have all requests to URLs other than /assets, /ponzu and /api return a server side rendered Vue app by using os/exec and node to execute a bundled version of my app.

The ponzu part worked really good once I figured that the addons don't get autoloaded unless you include them in some other part of the app. I had to add _ "my/addon" to the imports of one of my content types to force ponzu to show my addon in the backend.

I didn't go further with this experiment because of other work but I might pick it up later.

Anyway, what kind of a frontend addon are you looking to build?

Around the same time I started playing with ponzu, I was also experimenting with a bolt inspired Go app with the echo framework where I wanted to register content types, routing and templates all at runtime with JSON config files. The idea was that you'd compile only once and then work on your frontend in a more dynamic way (I'm coming from PHP and Ruby so compiling is really weird to me for web development).

from ponzu.

krismeister avatar krismeister commented on April 28, 2024

My 2 cents is there are better tools for routing paths to different applications. traefix for instances makes this easy. If you want React Universal, thats great, you can stand it up with express, and route any path not /api or /admin to your express app.

The REST Service CMS trend is gaining alot of traction. Focusing on the best CMS possible and not view-rendering is what attracts me to Ponzu.

@martinsotirov for the JSON models this is the way that systems like contentful or other hosted CMS solutions configure their models, and the JSONs stored within their database. I agree its super convenient for developers and for migrating content across servers. The content and the models transfer with a database sync.

from ponzu.

penguinpowernz avatar penguinpowernz commented on April 28, 2024

Seems that the API is not a REST interface. Should have gone with something like gin or gorilla, since the HTTP stdlib is not smart enough to parse wildcards or params from the URL. Switching to one of these would allow an easier way to build REST paths for all paths you want exposed without having to resort to the ol' query strings.

from ponzu.

nilslice avatar nilslice commented on April 28, 2024

@penguinpowernz - thx for the feedback.

You can mount any router your heart desires on the stdlib http mux - making Ponzu as flexible as anything, so feel free. Ponzu is also intentionally released under one of the most permissive licenses allowing you to hack it up at your leisure.

from ponzu.

penguinpowernz avatar penguinpowernz commented on April 28, 2024

Wow you can?! I didn't know that, was searching the http docs and could see how... yet, I'll take another look.

from ponzu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.