question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mailing render server API; production mode

See original GitHub issue

Context

A few users have asked for a method of running mailing as a standalone process with an HTTP API. They’d like to use it from backends that don’t have access to react or can’t consume nodejs packages. The new API would have one endpoint that renders a template to HTML with input props.

Thanks to @sebasalvarado, @alan-francis, and @jdotjdot for describing the use-cases in #54.

Design

Currently the mailing preview server is intended only for development. That is, it’s built without any consideration for handling many requests and running for a long time unattended. Are there memory leaks? How many TPS can it serve? Are there spots we can switch to async IO? Let’s find out.

This design adds a “production mode” for the mailing server as well as the required API (which could also be useful for development mode features like editing props from the browser).

CLI change

With NODE_ENV=production set, mailing should start the server in production mode, running efficiently and indefinitely.

HTTP API change

GET /renders/TemplateName.json?props=JSON_PROPS

return values

200
{
  html?: string,
  errors?: object[] // prop type or template compilation errors
}
404
template not found

Tasks:

  • cli change outlined above
  • add API route above
  • jest tests for API route
  • manually test deploying this to fly.io
  • add instructions to README for setting up and deploying a standalone mailing server

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
jdotjdotcommented, Aug 29, 2022

somewhere serverless

@jdotjdot do you happen to have an example of a library that you think does this well? Examples I’ve seen of this (e.g. postgraphile 💙) usually build out an example repo on one platform rather than a portable feature built into the library.

My default for a serverless deployment of mailing would be shipping a next.js app to vercel and importing a render function from mailng-core in an API route kind of like we do in the demo video. Packaging as a next app might be useful because they’re ubiquitous and easy to deploy on any platform server-full or serverless. Would an example repo doing that be helpful?

Is this for an immediate use-case you have or more speculative? Just figuring out how to prioritize effort on this use-case.

Thanks!

Sorry for the delay on this one. This wasn’t for any immediate use case, just speculative. But it is a problem I’ve had many, many times. And it seems like you’ve already taken care of doing this in a serverless way! Really exciting!

It was smart to use Next.js here, it makes a ton of sense for this type of product. Serverless out of the box, and then you can just drop-in files to get them rendered as previews. I haven’t looked at the code yet but I assume there’s some way to get MJML in there as a renderer, since it’s just React under the hood.

1reaction
jdotjdotcommented, Jul 27, 2022

Another thought on how to deploy it: I’d be pretty fine with “production mode” for this actually being a small binary or some way to package it up as a lambda or similar, since I would imagine most production calls would take the form of “send props, get back HTML”, potentially also with a validation step of some sort. I don’t necessarily need an entire server for this, I’d be fine to have this somewhere serverless.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Deploys Work | Render · Cloud Hosting for Developers
Render makes deploying your application as easy as pushing your code to source ... Render will automatically build and deploy your services with...
Read more >
Deploy Node js API with Env Variables on Render ... - YouTube
00:00 Introduction 00:38 GitHub - Signup 02:30 GitHub - create repository02:58 Render.com - Signup 03:52 Local Node.js Project Demo 04:10 ...
Read more >
Express Tutorial Part 7: Deploying to production
The production environment is the environment provided by the server computer where you will run your website for external consumption.
Read more >
Development Mode and Production Mode | Looker
Use Production Mode when you are exploring data in Looker for your own analyses or to create saved content (Looks and dashboards) for...
Read more >
Rendering Images from node Backend on React App in ...
jpg>. Also In a tutorial I watched heroku build pack for create-react-app was used to build before deployment then under production environment ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found