Are Json files a reliable choice for storing data in Next.js applications?

I'm currently working on developing a video application that will offer both free and premium videos. With approximately 100 videos in the pipeline, I am contemplating whether setting up a database to store video links is necessary. Considering security concerns, I am exploring the option of reading them from a JSON file. However, I am unsure if files created within the src folder are accessible to users or not.

videos.json

{
  "introduction": "sd324d",
  "how-to-save-money": "824ds",
  "investments": "64hdxc",
  "do-it-yourself": "82jxcn",
  "final-project": "hd82hd"
}

video API

export default async function handler(req,res) {
  const { videoSlug } = req.query;
  const isUserPremium = // Implement user token verification

  if(!isUserPremium) return res.status(403).json("Not allowed!")

  const jsonDirectory = path.join(
    process.cwd(),
    `/src/content/videos.json`
  );
  const fileContents = await fs.readFile(jsonDirectory, "utf8");
  const objectData = JSON.parse(fileContents);

  const id = objectData[videoSlug];
  return res.status(200).json(id);
} 

The code functions as intended, but my primary concern lies with data security. It is important for me to ensure this aspect, especially considering my plans to deploy the app on Vercel.

Answer №1

In my opinion, it's best to avoid the practice of granting easy access to your files. One possible solution could involve setting up a node.js server that conceals all files from users.

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

The functionality of Mongoose async promise appears to be malfunctioning

Struggling with using async in conjunction with mongoose. Here's my code snippet : function() { SchemaOne.findById(fooIdOne).exec().then( x => { // Some initial instructions myCollection.foreach( y => { SchemaTwo.findById ...

Unable to import library in Angular framework

I'm currently in the process of setting up js-beautify, which can be found at https://www.npmjs.com/package/js-beautify I installed it using the command npm install js-beautify --save Next, I added the import to my app.component.ts file The documen ...

Retrieving Text between two specified strings (Command Line)

I am currently working on extracting song names from a json file retrieved from the Spotify API. The term "name" is used for both artists and songs, but my goal is to extract the song titles. My initial attempt involved using grep, but I am struggling wit ...

Angular Universal Resolve

I am trying to ensure that an asynchronous call completes before any of my routes are resolved by modifying route.resolve as follows: var originalWhen = $routeProvider.when; $routeProvider.when = function(path, route) { route.resolve || (route.resolve ...

Tips for showcasing an array in PHP with either JSON or XML structure?

I am currently working on creating an API web service using PHP. My goal is to display all the records from my database table in both JSON and XML formats using arrays. However, I am facing an issue where only one record is being displayed or receiving a r ...

Is there a way to replicate onbeforeunload in a Vue.js 2 application?

I have a Vue component that is monitoring whether it has unsaved changes. I want to alert the user before they move away from the current form if there are unsaved modifications. In a traditional web application, you could use onbeforeunload. I tried imple ...

Working with JavaScript Arrays within a JSON file data

I am currently learning React and attempting to display random images from the Picsum website using their API. The JSON file I receive contains various information, but I am specifically interested in extracting the image URLs. Although it appears that my ...

Transformed the Next.js Pages Router into an Application Router

Looking to make a change in my API written with Nextjs's Pages Router. Currently, it serves as a proxy for downloads and I am interested in converting it to the App Router method. Does anyone have any guidance on how to go about implementing this? imp ...

How can I retrieve all values that share the same reference number as an object in a JSON file using iOS and Objective-C?

This is an excerpt from the JSON response received from a web service. - Books :[ -{ RfNo:"1", SegOrd:"1", LegNo:"1", Title:"Wild Elephants", Author:"Dr. Vijitha Perera", Country:"Sri Lanka", Price:"$8.99" }, -{ ...

Using Angular to convert HTML into a JSON file

After learning about ngSanitize and ng-bind-html, I am wondering if I can implement it within a ng-repeat. In my scenario, the logic looks like this: <div ng-repeat="(k, v) in specs.webdev"> <h3>{{::v["job-title"]}}</h3> <p> ...

Implement a redux-form within a react-bootstrap modal

I am facing a challenge with incorporating a multipage 'redux-form' form into a react-bootstrap modal. My goal is to have the form displayed within the modal overlay when the modal is opened. How can this be achieved? The code below is producin ...

Unravel various models in PHP Symfony by decoding JSON data into objects

Is there a way to effectively convert a multidimensional JSON into an object or model? When attempting to convert a JSON with nested structures, only the outer layer is successfully converted while inner layers remain as arrays. How can this issue be reso ...

D3 bar chart displaying identical values but with varying data sets

<!DOCTYPE html> <html lang='en'> <head> <meta charset="UTF-8"/> <title>Interactive Bar Chart using D3</title> <script src="https://d3js.org/d3.v4.min.js"></script> </head> <b ...

Navigating to a different directory using Node.js and ExpressJS route mapping

I'm struggling with setting up routing using ui.router. This is the structure of my folders: https://i.stack.imgur.com/Fu0A9.png In the app.js file within the javascripts folder, I have the following code: var app = angular.module('testing&ap ...

Mixing box-shadow and blur filters can result in unusual artifacts appearing in Webkit browsers

Recently, I encountered an intriguing and frustrating bug in WebKit browsers. Consider a scenario where there is a parent DIV (let's say .wrapper) and a child DIV (.main). You apply a box-shadow on the .main DIV and a blur filter on the .wrapper DIV. ...

Differences between REST and RPC in PHP

As I work on my Ajax website, I find myself pondering the choice between using REST or RPC. If only my server supported Servlets, I could easily solve this dilemma by installing persevere. Unfortunately, that's not an option with my current server se ...

What is the most effective method of testing with jest to verify that a TypeScript Enum list contains all the expected string values?

Recently, I created a list of enums: export enum Hobbies { Paint = 'PAINT', Run = 'RUN', Bike = 'BIKE', Dance = 'DANCE' } My goal is to iterate through this list using Jest and verify that all the string ...

How can I incorporate Bootstrap 5 into my Storybook setup?

As I work on constructing a storybook, I am exploring the idea of integrating Bootstrap 5 into it. I am wondering if the most effective approach to implement it is by utilizing a preview-head.html file within the .storybook directory. Despite my efforts ...

What could be causing the inaccuracies in the way my Array data is being transferred to my MySQL

Recently, I had the opportunity to learn how to convert a JSON file into an array with the help of a generous stackoverflow user. The process was successful, but when I attempted to input this data into my database, I encountered unexpected results. Array ...

Challenge in WordPress Development

As a beginner in website building, I am looking to customize the background of my pages with a solid color. The current SKT Full Width theme I am using has an opaque background which is causing the text on my slider to blend in and not look appealing. All ...