Showing video player on Node JS simple route - node.js

I have very simple node js application using express.
I have written route as below.
app.get("/", (req, res, next) => {
res.status(200).json("Application is up and running on port 4003!");
});
It was running quite well, was showing "Application is up and running on port 4003!" as expected but now, it suddenly showing up window as below and same for all other routes too.
I have not added video tag anywhere in my application.
What I did wrong?
Similarly I tried to run in postman and showing as below
Here is response header

Related

react and node js serving from single port endpoint not found

Im making a simple app with react and node. On the react side I create a note with a unique-id and then the note can be found at mypage.com/unique-id using react-router-dom and useEffect in the loaded component to get the data from the database. This works perfect as long as my frontend and backend are being served from different ports. When I build the react app and place it in my nodejs app the app will work fine, until I reload mypage.com/unique-id and then im hit with a 404 on my server side. I have a bit of a grasp of what is going on - everything is being served from localhost:3001/ so when i reload localhost:3001/unique-id my server is looking for a route for that, which doesnt exist on my server side. I'm not sure how to connect the dots to serve my front end page at localhost:3001/unique-id with data from the server for that unique id. If i makea route on my server side it would just send back the raw data without serving the page that is suppose ot be at localhost:3001/unique-id
I had faced the same issue and it got resolved by adding * into the route
before route
app.get("/", (req, res) => {
res.header("Cache-Control", "max-age=-1");
res.header("Expires", "-1");
res.header("Pragma", "no-cache");
res.sendFile(path.join(__dirname, "build/index.html"));
});
after
app.get("/*", (req, res) => {
res.header("Cache-Control", "max-age=-1");
res.header("Expires", "-1");
res.header("Pragma", "no-cache");
res.sendFile(path.join(__dirname, "build/index.html"));
});

nodeJS not found on firebase

:)
i have a nodeJS app on firebase, the front of this app is do with ReactJS.
As long as I do not update the web page everything works perfectly, but if I update, nodeJS takes priority over the url and displays an error because no action is defined for the url
I made a sendFile to the index.html for each url like that :
app.get('*', (req, res) => {
res.sendFile('index.html', {root: `${__dirname}/../public`});
});
Locally, it works perfectly, I can update without losing the page where I am, but when I deploy my application on firebase it does not work. during the update it shows me "not found" and that in the console of the browser
console of the brower
I thought that it could not find the file because firebase arranged them differently but I did not find anything concerning the architecture of firebase :/
I don't know if it's completely clear, I don't know how to explain it better ^^ '
thanks for your time :)
I found!, firebase apparently does not allow the code to leave the function folder (donation impossible to do ../public), so I simply put the public folder in the function folder .
Its gives its:
app.get('*', (req, res) => {
res.sendFile('index.html', {root: `${__dirname}/public`});
});

Applying SSR / social media sharing to selected routes in Angular 7

We made a late decision to implement social media sharing for Angular 7 project. As a first step of the re-write I wish to dynamically update social media tags for a particular route only ('/post/').
I am able to apply SSR on '/post/' using app.use in the server.ts file:
app.get('/api/**', (req, res) => { }); // ignore api requests
app.use('/post/', (req, res) => {
res.render('index', { req });
}); // successfully serves SSR content on '/post/' but client side rendering fails to take over.
app.get('*', (req, res) => console.log('Other routes')) // 'ERR_EMPTY_RESPONSE' error
I am running off localhost:4200 for both server and client - spinning up the SSR node server with npm run serve:ssr, and spin up the client side with ng serve.
I am unsure the best way to handle requests for different routes. How can I tell Node to skip other routes and to spin up Angular on the client side? Currently it returns 'ERR_EMPTY_RESPONSE' error on other routes and only provides SSR content for '/posts/' (no client side rendering).

Node.js and Express not working?

I am currently trying to learn implementing RESTful APIs using Node.js & Express. Using this tutorial: http://code.runnable.com/U7bnCsACcG8MGzEc/restful-api-with-node-js-express-4
I created each file on my local drive and tried running the code using node server.js..However I kept on getting an error. Why might be causing this?
The code you chose to run is only routing requests for urls that begin with /api as you can see here:
app.use('/api', router);
On top of that, the routes it accepts are /players and /player/:id:
router.get('/players', function(req, res, next) {
res.json({ players: players.getAllPlayer() });
});
router.get('/players/:id', function(req, res, next) {
var player = players.getPlayerById(req.params.id)
res.json(player);
});
For every request, including the routes above, it outputs the method and url to console.log.
Even when it fails to get /, you should see GET / in your console.
Now try to access this url: 0.0.0.0:8080/api/players
It works, right?

Express api res.jsonp returns double callback

I have an Express server running at port 8080 with this route
app.get('/api', function (req, res) {
res.jsonp('user API is running');
});
I open a browser window to
http://ec2-54-226-27-72.compute-1.amazonaws.com:8080/api?callback=hello
The response in the browser is
hello && hello("user API is running");
Why are there 2 hellos? Is this a proper JSONP response from Express and will it be processed correctly by a client?
Yes, that's the proper format. The purpose of the first hello is to make sure that the function hello exists on the client before trying to call it (an error would occur if the function did not exist).
There's a little bit of info about this in the preview chapter of the express book here. I just read it the other day.

Resources