Denying access to partial views with node.js/ express? - node.js

How would I go about denying access to a partial views with node.js/express? I have various different views in my single page web app and would like some pages to not be shown unless a user is logged in. How would I go about doing so? I know this might be vague, but I would like to have a general idea before actually coding in anything.
EDIT:
for example,
since my page is a single page app everything should be pulled up on the main page when any certain button is clicked, and the URL be handled from my side. But, I have the issue that if I type in something like:
http://www.mypage.com/login
the elements load, but they come out wrong. I would like to block the views from showing up unless they are clicked from a button on the main page. How would I do so?
Your help is appreciated.

You can do the basic routing logic and call a method for routes which you want to restrict.
app.get('/partials/view1, routes.partials);
app.get('/partials/voew1', restrict, routes.partials);
In the restrict method redirect the flow to a generic 'restricted' view.
Check this : https://github.com/visionmedia/express/tree/master/examples/route-separation

Partials were obsoleted in Express 3. It's usually better to use the latest version of software.

Related

How to: allow users to create their on pages on web app?

I'm relatively new to webdev, and essentially I'm trying to create functionality that allows users to create their own event pages (similar to Facebook Events, Meetup etc.).
My question is to do with the surrounding architecture of this, namely:
Given each event page will have its own url, do you need a separate file for each event in the backend?
Or is there some clever way of templating and directing traffic? (Sorry if this is vague, I'm trying to probe if there is a better way of doing this?)
I notice that most of the FB/Meetup events all have their own URLs, does this mean that they all have separate files in the backend?
I'm using Nodejs for the backend btw.
I've been Googling around but haven't been able to figure it out, I think I might be using the wrong wording... so even a point in the direction of the right wording would be much appreciated!
Thanks y'all
Generally this is handled via database-driven solutions. The "pages" are dynamic, and the URL is a parameter see #Konrad's comment that allows the pages to be looked up in a database which allows the dynamic content to be loaded into a single page which handles the complexity of each page seeming unique.

How to graphically select a element on a page outside the own website

So, I have a website where i need to insert a lot of products from our suppliers' website, and I would like to automate it.
I was reading this question, that would solve most of the "front-end" part, and on the backend than I only need to get the link of the page, and use a basic web crawler library to search on that page the given selector.
However I'm missing the part where I inject a possible JS library on the supplier website, in order to allow others to select the element with the mouse, and not to find it using something like the Chrome console.
I was thinking about fetching the source page on the server side, and that returning it, but all the resources like CSS, JS, images, will be blocked by CSRF protection, and so here's my question:
Are there ways to do this in any way?
Edit:
ok maybe it's not so clear what I want to achieve... here's how thing should go:
Someone decides to insert a new supplier, that he should set the CSS path for the product name, the CSS path for the product description etc etc (section where i appreciate suggestion), and then he only needs to insert the products links and the server will get the informations using the CSS path inserted before.

MVC5 how to make db calls for a layout page

I have a MVC5 app that is using layout page to control the header and footer ect. The layout page has some sections that are database driven such as the nav bar. I am not sure of the best practice for where to make these calls is. I can think of 2 ways but neither are perfect
Method 1: Pass in data with the pages view model. Don't like this approach has my homepage controller should only be concerned with homepage content, not the layout. This would have to be repeated for each and every view.
Method 2: Ajax to WebAPI controller. Kinda leaning towards this, although I think this means losing stuff like #URL and #HTML which are being used to create links and render custom content.
EDIT: Though of another method
Method 3: Load info into cache on Start. Since this is not info that changes often after initial setup and this code is displayed on every page, caching would be needed anyways.
You should call a controller method from within the view. On your view:
#Html.Action("MyAction", "MyController")
Make sure this action can find everything it needs without having to have values passed in, and you're set. We do this in several projects via service location and/or dependency injection.

Hiding route parameters

I am learning nodejs with express and i am creating my first single page application with the help of knockoutjs, i have a lot of routes and i am looking for a way to hide the parameters in the Url other than encoding them, if i have header links like :
http://www.mywebapp.com/login
http://www.mywebapp.com/logout
http://www.mywebapp.com/signup
http://www.mywebapp.com/users/username
http://www.mywebapp.com/users/1-8
can i still make those links appear as
http://www.mywebapp.com
no matter what the route to be called is?
if not possible can someone please explain why?
my application is completely ajax driven.
Well if your app is ajax then the url won't change. You can also wrap the entire thing in an iframe and only navigate inner frame. But keep in mind that this is generally bad practice as history and bookmarks don't work.

How to make a asynchronous app with Node, Express

I'm working on an app that i being built using Node and Express. All is fine, however the app is currently not asynchronous and I'd like it to be, so I'm currently investigating what would be the best way to do it.
As far as I can tell, socket.io seems to be the preferred choice to go with Node.
My question is, is socket.io's methodology the best way to move data between the server and client or is there a better, more robust way to do it? Maybe something accomplished with Node only?
PS: I think socket.io sounds really nice. Its just that I'm new to Node and though there would be a simpler way to move data back and forth.
Many thanks
EDIT:
Ok, I've seen the term "realtime" used before and was frown upon. The commenter implied that technically there is no "realtime" application, hence me choosing asynchronous, however realtime does describe what I'm after: An app that will be all ajax-like. For instance, in my app, when I need to edit a saved document (mongodb records are called documents), I need to redirect the page passing the document id as argument. I don't want that. I want all through ajax. I can achieve this with jQuery, however behind the scenes the server will still be moving through urls (I'll need to create loads of app.get('product/:id/edit', ...), app.post('/product/:id/edit'. ... and then use $.ajax to get and post stuff ) so I was wondering what's the best way to achieve this.
PS: I might be looking at this completely wrong. Like I said, I'm new to Node and for app development for that matter.
EDIT2: An example: Let's say I have a page with a table in it where I list all products. Each product will have a EDIT/DELETE button. At the moment, when I click edit, I'm redirected to another page where I can edit the product and save it, then I'm redirected to the product listing. I'd prefer to load the product into a modal window, make whatever edits I need, then update the product/listing without leaving the page.
Using $.ajax I can use the product ID, enquiry the db for that particular product, populate the field in the modal with the product details and display to the user. Then allow the user to make the changes and update the products, however the part in which I need to enquiry the db in order to populate the modal is muddy because the id needs to be passed through the url...
I don't know how to pass the id to the application unless is through app.get('/product/:id/edit', ...) then app.post('/product/:id/edit').

Resources