"Dynamically generated websites, backend processing, React framework Nextjs, Content Management System WordPress

I'm interested in creating a primarily static site using Next.js, but I also need the ability to provide customers with price estimates based on their specifications. The calculation process needs to be kept private and not exposed to anyone else (otherwise, I would have used plain javascript). I assume that I'll need some kind of server listener to handle requests and respond with the calculated price.

I currently use Host-Europe's Webbuilder pack and have SSH access. Setting up WordPress was as simple as copying over the files and linking the domain to the WordPress folder in Host-Europe's admin panel.

My main queries are:

  • Can I easily add this functionality to a static website framework, or should I consider switching to a server-side rendering framework like WordPress, React, Django?
  • Do I need a background process listening for requests? How can I trigger a server-side function via JavaScript and retrieve the response?
  • Why wasn't a daemon process necessary for WordPress to function? Could Host-Europe be handling this in the background?

If I opt for a framework, I'd prefer either Node/JavaScript or Python, but I'm open to anything that gets the job done efficiently. While I've built a static blog hosted on GitHub Pages before, I feel slightly lost when it comes to more advanced tasks.

Answer №1

  1. To enhance security, consider performing calculations in JavaScript, fetching data from an external source stored on your server, and minifying the javascript code for added obfuscation.
  2. Another option is to take advantage of AWS Lambda functions which offer the first 1 million requests free of charge.
  3. For a straightforward approach, you can develop a basic REST API using Node.JS and Express JS.

Example of Node.js Express.js API

const express = require('express')
const app = express()
const port = 3000

app.get('/calculate-price', (req, res) => {
  response_price = req.query.parameter1 + req.query.parameter2
  res.setHeader('Content-Type', 'application/json');
  res.end(JSON.stringify({ price: response_price }));
})

Utilizing the fetch function in Next JS

export async function getStaticProps(context) {
   const res = await fetch(`https:[your API or cloud function resource]?parameter1=abc&parameter2=1245`)
   const data = await res.json()

  if (!data) {
    return {
      notFound: true,
    }
  }

  return {
     props: { data }, // the price will be passed to the page component as props
   }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible for Netbeans 7.3 to debug a PHP script when triggered by a JSON request?

In my Netbeans 7.3.1 setup, I usually have no issues debugging PHP files with Xdebug when my site project is structured to generate the site directly from PHP code. However, I'm currently working on a site that consists mostly of HTML files and only h ...

Leverage Angular's constant feature in scenarios that extend beyond the

Even though it may not be recommended, I find it fascinating to use Angular services outside of the angular framework. One example is having .constant('APIprefix','/api') I am curious about how to access the value of APIprefix outside ...

Ensure that every route is prefixed with /api

Is there a way to set all routes accepted by Express to start with /api without explicitly defining it? Current: this.app.get('/api/endpoint-A', (req, res) => { return res.send('A'); }); this.app.get('/api/endpoint-B', ...

Generate a key pair using the cryto library and then use it with the json

There's a new method called generateKeyPair in node 10, and I am utilizing it in the following way: const { publicKey, privateKey } = crypto.generateKeyPairSync("rsa", { modulusLength: 4096, publicKeyEncoding: { type: "spki", format: "pem ...

Steps to set up gapi-script authentication with next-auth in a Next.js application

I have encountered an issue while working on my open-source project that involves utilizing the Google Drive API. Can anyone guide me on how to set up gapi-script authentication using next-auth in a Next.js project? I have managed to implement authentica ...

What is the best way to include a form within every row of an HTML datatables structure?

I have a regular table that is populated with data fetched via Ajax, and it appears like this: Ajax <script> $(document).ready(function() { $('#mytable').DataTable( { "ajax": "myurl", "dataType": 'json', ...

Sign up for the observable, retrieve the asynchronous mapped outcome with input from the dialog, and then utilize the outcome from the map

Currently, I am utilizing an API-service that delivers an Observable containing an array of elements. apiMethod(input: Input): Observable<ResultElement[]> Typically, I have been selecting the first element from the array, subscribing to it, and the ...

Trouble encountered when attempting to override styles in Material UI's TableRow

I am attempting to customize Material UI's default styles in order to create a margin between each TableRow. Despite my efforts, it appears that the override is not being reflected in the user interface. ...

Tips for creating a stylish scrollbar in a React Material-Table interface

Currently, I am utilizing the react material-table and looking to implement a more visually appealing scroll-bar instead of the default Pagination option. Although I have experimented with the react-custom-scroll package, it has not produced the desired ...

Why are the destinations not sorted in ascending order?

I'm trying to pull destinations from the database and arrange them alphabetically using the following code: $destinations = get_posts( array( 'post_type' => 'destination_showcase', ...

Prevent the onClick event from being triggered by utilizing JSON data

I am trying to implement a feature where a button click is disabled based on a parameter fetched from a JSON file: JSON Parameter "reactJson": { "disable:"true" } Currently, my onClick method is functioning correctly. However, ...

Are there any compatibility issues with uuid v1 and web browsers?

After researching, I discovered that uuid version1 is created using a combination of timestamp and MAC address. Will there be any issues with browser compatibility? For instance, certain browsers may not have access to the MAC address. In my current javaS ...

Removing an element from an array within MongoDB

After closely examining my mongodb data structure, it appears like this: [ { "_id": "582bc918e3ff1bf021ae8b66", "boardName": "Test Board", "created_at": 1479264483957, "__v": 0, "person": [ { "name": "Steve", "w ...

Tips for removing unnecessary debugging code from JavaScript when compiling or minifying your code

Back in the day, I would always include tons of debug code in my JavaScript app. However, I'm now searching for a method that will eliminate debug code during the compilation/minification phase. Does the world of JavaScript have something similar to ...

Maintaining aspect ratio of canvas while ensuring responsiveness

Currently, I am working on a drawing app and have come across an issue that has been challenging for me to resolve. The dilemma lies in resizing the canvas of sketches from the original resolution of 1280 x 720 to the maximum size possible upon opening the ...

Deactivate a button when clicked on a card that has been mapped

After creating a card component and mapping through each card, I added an onClick function to disable the button of the clicked card. However, my logic ended up disabling all buttons instead. Here is the code snippet where I define the rendering of the UI ...

Adjust the size of the event bar on the FullCalendar resourceTimeline view

In my implementation of FullCalendar v6, I am displaying 6 months worth of data in the calendar, with each slot representing a one-month period. The issue I am facing is that when creating an event spanning 10 days, it currently takes up the entire width o ...

How to style the second child div when hovering over the first child div using makeStyles in Material UI

I am working on a web project with a parent div and two child divs. I need to apply CSS styles to the second child div when hovering over the first child div. Below is the structure of the render method. <div className={classes.parent}> <div c ...

Retrieve data from an array within the user Collection using Meteor and React Native

I need assistance with retrieving the entire array [votes] stored within the User Collection. Below is the JSON structure { "_id" : "pziqjwGCd2QnNWJjX", "createdAt" : ISODate("2017-12-21T22:06:41.930Z"), "emails" : [ { "a ...

Learn how to create a half and half color scheme in an HTML table

I have created an HTML table that resembles a calendar. Various events are registered in the calendar, each distinguished by its color. However, I am looking to change the colors of the cells to be half and half. https://i.sstatic.net/gaQq2.png The imag ...