Is it possible to set up a URL as a substitute for another URL?

Looking to have cdn.ex.com/avatars/:UserID redirect to my cloud public file URI:

https://cloudapi.com/account.cloud.com/files/uploads/avatars/(userid)/avatar.png
(actual URL provided) No code currently, but planning on implementing the following:

app.get('/avatars/:userid', (req, res)=>{
    let userid = req.params.userid
    let uri = `https://cloudapi.com/account.cloud.com/files/uploads/avatars/${userid}/avatar.png`

});

Desired functionality in HTML:

<span>Username</span>
<img class="pfp" src="cdn.ex.com/avatars/671856275627525">

Rather than manually inputting:

<span>Username</span>
<img class="pfp" src="https://cloudapi.com/account.cloud.com/files/uploads/avatars/671856275627525/avatar.png">

Advice on achieving this would be greatly appreciated.

Answer №1

After some searching, The solution involves utilizing node-fetch to retrieve the resource Subsequently sending the data as a buffer Whether it's embedded in a tag or accessed directly via a link, it should function properly. Simply navigate to Google and search for node-fetch then visit its npm page and search for Buffer Finally, use res.send(buffer) instead of fileType(buffer) and eliminate the last line. Special thanks to @Marc for his assistance (as seen in the comments)

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 Mongoose query for the id field retrieves both the id and _id values

Within my Mongoose schema, there is a specific field named id which holds a unique identifier for each document. This operates using the same system as the standard _id field as shown below: var JobSchema = new mongoose.Schema({ id: { type:String, requi ...

The Express.js server seems to be having trouble rendering a static JavaScript file

Currently, I am in the process of constructing a website and have implemented an express.js server to collect data submitted through a form. Prior to configuring the server, I had already developed the site using static js and css files. Once the connectio ...

Providing arguments to mocha while executing through npm

I'm currently setting up nyc/mocha for my project and I need to pass the --exit option to mocha when running it with or without nyc. Below is a snippet from my package.json file: "scripts": { "start": "node ./app", "test": "./node_modules/.b ...

Removing unexpected keys during validation using Joi

Within my server-side JavaScript code, I am utilizing Joi for validating a JavaScript object. The schema being used is structured as follows: var schema = Joi.object().keys({ displayName: Joi.string().required(), email: Joi.string().email(), e ...

Sending emails from Node using Mail (nodemailer/maigun-js) is not functioning correctly

Seeking to ensure complete registration confirmation, I am attempting to send a confirmation email to the user in the process of signing up. My chosen tools for mail sending are node.js along with either nodemailer or mailgun-js. During testing on localhos ...

Encountered a Gulp error: unable to spawn process due to E

gulpfile.js 'use strict'; var gulp = require('gulp'); gulp.paths = { src: 'src', dist: 'dist', tmp: '.tmp', e2e: 'e2e' }; require('require-dir')('./gulp'); gulp.ta ...

Transmit data using both jQuery and JSON technology

I'm struggling to figure out how to send a JSON structure with a file using AJAX. Whenever I try to include an image in the structure, I encounter an error. var professionalCardNumber = $("#professional_card_number_input").val(); var professi ...

Request body is null if accept-encoding is set to 'gzip, deflate'

I'm struggling to capture data from a webhook sent by a third-party source. Despite verifying that the content-length is greater than 0, inspecting req.body only returns {}. The webhook is directed towards the route '/v2/wtevr/report/wtevr'. ...

Use the Nodejs HTTP.get() function to include a custom user agent

I am currently developing an API that involves making GET requests to the musicBrainz API using node.js and express. Unfortunately, my requests are being denied due to the absence of a User-Agent header, as stated in their guidelines: This is the code sn ...

Managing ajax requests, failing to retrieve information

I am struggling to configure my client-side ajax calls to send data to a node express server. I want the ajax request to be triggered "onclick" of an href link. My goal is to pass the ID of the link as a variable to the server, but unfortunately, the serv ...

Issue: Unable to find a compatible version of chokidar. Attempted chokidar@2 and chokidar@3 after updating npm to version 7.*.*

After using ejected CRA, it compiled successfully but then broke with the following error. The issue started to occur after updating npm from version 6 to 7. You can now view webrms in the browser. Local: http://localhost:3001 On Your Netw ...

botkit-sms: Enhancing functionality with middleware extension

Currently, I am attempting to integrate the api.ai middleware plugin with botkit-sms. However, I am facing issues while debugging the source code. It would be greatly appreciated if you could offer some insights. You can find the source code of the librar ...

After clicking on the checkbox, req.body.task becomes undefined

Whenever I click on the checkbox, the value of req.body.task returns as undefined. <input type="checkbox" name="task" autocomplete="off" checked="" onchange="onToDochange({{id}})"> This function is triggered by a change event on the checkbox and it ...

Validating a string with Hapi Joi validation for singles

Looking to perform basic validation on a single string, specifically the request header X-Value. Here's what I have tried. The issue I'm facing is that it always returns 'success' even when there is no X-Value header present. const ...

Auto-refresh the page upon any updates made to the MongoDB collection

I'm currently working on a Node.Js project that involves MongoDB integration. I'm looking for a way to automatically refresh one of my HBS pages whenever there is a change in my MongoDB collection. I could use some guidance on the best approach ...

Deployment of an Azure web app using Node.js is encountering issues due to a missing npm

Hey there! I'm running into an issue while trying to deploy my Azure web app using Azure Pipelines from a git repository. Everything works perfectly fine locally, but when deployed, I keep getting an error saying that the package is-docker is missing ...

Ways to determine the character count of a message in Socket.IO

How can I retrieve the length of a socket io message (in a variable)? I attempted to use this code below, but unfortunately, it did not yield the desired result. socket.on('message', function (message) { var messagelength = message.length; / ...

Error encountered while populating mongodb database with nodejs

Currently working on a nodejs, express, mongoose project and attempting to seed the database. MongoDB is activated but when I try to run the following command: $ node product-seeder.js (node:2810) UnhandledPromiseRejectionWarning: Error: Invalid schema, ...

Using middleware in Express to handle GET requests

Can the request object sent to any route be accessed globally in Express, without having to explicitly access it in a .get method or similar? ...

Create a package that is compatible with both node and browser environments

After successfully creating a node NPM package that acts as a wrapper for a specific JSON API using node's http, https, and querystring modules, I am now looking to expand its usability by making it compatible with browsers. This would involve replaci ...