Express with PHP-Like Folders - node.js

Instead of just using Express for single-page-sites and web applications, I've recently been trying to use express to replace a php Intranet site, where the site has many different pages and some of those pages are just intended to be totally different from others on the same site.
As I develop web pages on Express, there's one aspect (and only one) of php I kind of miss and that is:
With php you could easily group all static-files related to a particular web page into one folder with the server-side-scripting.
For example, sometimes a page I create has static files and views that are not going to be needed by other pages in the entire site, and for pages like this, I like to just put all the images, client-side-javascripts, css, and server-side-scripting into a single folder. Later, if I need to edit this page, I can go right-click on that folder and open all related files (client-side and server-side) in my text-editor at once.
With Express, I have to create a route in one place, put static files in a folder some other place and create views in yet another place. Later when I want to open up all the files related to the page, I have to go to multiple places to get all those files tabbed into my text-editor.
With php, there was no need to create a route. By simply placing an index.php file into a folder the route was created. Then, placing all page-related resources into that same folder was no problem for php.
I am no fan of PHP; I've never liked it as a scripting language. Yet, every once in a while I miss certain aspects of it. This is one of those aspects.
Has anyone published an app.js file where, during first launch, it recursively scans the application's folders auto creating routes based on the fact that a folder contains an index.js file in it? Also, such a script would also have to make all other files in these folders static, except for server-side-resource files like views and server-side scripts.
I'm not even sure this is a good idea, but I'm curious if anyone has attempted to build something on top of express that acts similar to what I'm describing.

Related

Can I change files in the sharepoint \ LAYOUTS \ folder?

I know we shouldn't and I have never done this before, but something came up that I need to do, change a color in a .css file in the \ LAYOUTS \ folder and the context of the current solution does not allow me to change this color in a simple way otherwise not be messing with the color source file.
I believe it will not impact anything, but I am still looking for information about this change.
Can I go on with this?
I would not recommend it.
Of course it is fine to add some application page to _layouts folder to include a reusable page which might be used on any SP site or add some css or images or js which might be included in any SP site or masterpage used globally, but I think it is not ok to modify the OOTB files from _layouts folder, as we may not always be aware of all the places this particular script or css or other is used. So to sum up, it might be done, but as a last resort, but it is ok to include some new file and use it (best by proper SP project or mapped folder in the project).
My understanding is that this location store files (like js, css, images, or application pages) which may be used on any SP site by simply going to /_layouts/ path
For more information please check this link

Sitecore + Mvc Application. Proper redirection without losing Google indexing. sitecoredomain.com/mvcapp

I have big dilemma and I need help.
Basically we have sitecore web app this is our main web service. Currently my app is working with the main app via .html static pages(it works as SPA, JS calls backend with needed html content).
But database I work with grows bigger, and to access certain elements with URL I need to create ~70.000+ static files. As well this static files are needed for google indexing, so we can advertise our products. In case if there is new meta data needed or new item added, I need to run my other program that creates this static files to update everything out of txt file with all items. And we have 2 reserve servers where our sitecore web is. So it like 70k+ files for 9 languages and 3 web servers. It takes a day to recreate everything...
That why I decided to make clear MVC SPA application, and it works great. But...
I can't add my MVC application or anything except .html files to the current sitecore main app.
And the question is: how it could be done without losing google indexing and without changing main domain.
For example we have now:
www.ourdomain.com/foldername/mystaticfile.html
What I want:
www.ourdomain.com/mynewmvcapplication
Sitecore has a settings called IgnoreUrlPrefixes. You can add mynewmvcapplication to this setting, in that case Sitecore will ignore that path as well as anything under it. Here is a good article which shows you how to update this setting without making an update to Sitecore's config files.
Take a look at Sitecore Redirect Manager Sitecore market place. This it has the capabilities to create your custom url and keeps your search engine rating.
https://marketplace.sitecore.net/en/Modules/Sitecore_Redirect_Manager.aspx
Otherwise you can check Custom Link Provider and Custome Item Resolver. This will need more coding than the previous one. A google search with those keywords brings back many results.
Best wishes.

How to build vue views from within electron apps to mount as plugins

I am writing a reporting app that runs in electron. Reporting means I have a data source and users write views that arrange the data in whichever ways they like so it can be printed out or archived as PDF.
Let's say there is a list of student data along with grades for courses. The reporing app allows you to create a report that has a data table with names and grades for each course. So you end up with grade reports. Someone else wants just names and addresses another one wants to create a library card for each student. HTML and CSS combined with Vue make a great foundation to write this stuff.
The easy part is to fetch data from the database and offer json as a data source to views. The difficult part is how to let users add their reports to the app. In dev mode I can just add views to directories, import them and render the data as part of the app. But I have my views available at build time. Once I have built and shipped the production app it's out of my hands and the user can't add their views to the app anymore because they don't rebuild the app. They just want to point to a directory, add their views and use them.
I have decided to use single file components because they allow users to simply add calculations and maybe use pug etc to keep it simple. Besides I can store data about the component in a straight forward way (like name of report, department etc)
To my knowledge I need to build those views programmatically and load them dynamically.
So my questions are:
How can I build and mount single file components (.vue) dynamically
from within a production app that has no prior knowledge of user
produced files?
Do I need to build these components or is there a way to utilize on board tools to just read and render these components?
Is there a better way to serve these files?
More information:
Security is not a concern. So loading user created views is ok. It needs to be working in electron. I do have a server based app written in Ruby that does the same thing but the server is going away anytime soon so it has to be client based and executable. I cannot install node on client PCs so they could just build their own app and include their own views via hot reloading.
If you're interested in reporting apps there is one in JS but server based: https://jsreport.net/ or mine, ruby based: https://github.com/hmt/sahib
You could watch the directory and respond to new files being add. That's for the dynamic part of your question. A nice way is node-fs.
Using the same lib you can serialize and deserialize object to or from file, letting you load the file from your user.
At this point, you only need to be able to change back and forth from an object to a Vue component. As far As I know, this is no problem as you can
new Vue (object)

Can you copy a website?

Can you copy a Composite C1 website? I would like to create a copy of an existing website as a new website.
I start by creating Site A. Then I want to copy it and create Site B.
For example: copy the pages, functions, data, content, layouts, css from website A to website B. The only difference between the two would be the name.
It would infringe copywrites and may get you sued, but yes, its possible with a scraper, which basicly get all of the site, and download it to you, such things are used by google and search engines for a cache of sites.
Some exaples:
http://www.grepsr.com/?adwords2&gclid=CIe4rrPF57cCFURcpQodASIAgg
http://info.kapowsoftware.com/WebScrapingDefinitiveGuide.html?pi_ad_id=11920224743&gclid=CPCfxbTF57cCFWNNpgodnCQAKQ
http://scrapy.org/
or just google "web scrapers"
If you own the site however, and have access to the ftp, just simply copy the files to a folder called /b and it can become www.a.com/b or you can set up an addon domain to point to /b and make the addon domain.... say www.b.com
The answer to your question "can you copy a website?"
Is Yes....you can.
Provided you have access to all the files/folders, its no different then copying a bunch of folders on your computer, to another folder.
So if you're using a shared host....and everything is in your public_html folder.
Just put the whole website in one folder, then copy it over to another folder.
And then just simply point your new domain to that folder, through your hosting platform.
The process to do this is different for different hosts, but the actual answer to your question is...
YES....YOU CAN COPY A WEBSITE FROM ONE FOLDER TO ANOTHER
IF you have access to the files on the server you can simply copy it to the other desired location...
But remember you have to update links and other paths (if they are absolute).
If you don't have the access you could maybe use the developer tools like firebug, or using F12 on chrome or IE and copy each file and source code you have by hand. This approach is a little more time consuming than the last one but at least it can be made.
Cheers
As far as I know the easiest way would be use use Internet Explorers save to offline webpage function (if it is still there) - this will copy all the resources of the currently open webpage and recode the HTML to use them, as for an entire website..I dont think it will be easy, for legal reasons.
If it's your own site, sure why not! Who is there to stop you?
But if it's someone elses site, of course you have to worry about copyright and most of the time the website uses server side scripts which are not downloabeable.
You can duplicate a Composite C1 website by copying the entire file structure to a new folder and then update the installation id in the folder ~/App_Data/Composite/Configuration/InstallationInformation.xml (put in a new random GUID). Then point a new IIS site into this new folder.
If your site is using SQL Server as a backend you also need to create a copy of your database, create a new user account with dbo access for this database and update the connection string in ~/web.config.
If you wish to duplicate an entire page structure inside the existing instance of the CMS and share media files, templates etc. this could be done, but no tooling is available. This would be a coding task.
Copy the the directory(website physical path) where the website is pointing to and paste it somewhere...create a new website and point it to that copied directory....

Restricting access to files within a folder to webservice IIS6/7

I am looking for a way to restrict direct access to a certain folder or folders on our website which is hosted in IIS7 in our second dev environment, IIS6 in our first dev environment and IIS6 on production.
Basically we should be able to link to these files from our website i.e.:
http://www.domain.com/stuff/survey.pdf
But if someone tries to link to this from a blog post, etc. it should not serve the content. Is there any way to do this in a web config or is that beyond the abilities of IIS?
What I ended up doing was writing a PHP script which served content from outside of the web root, but only if the user was logged in and had a valid site cookie.
Then I created folders to replace all the content we were currently serving (.pdf, .png, etc.) since there was not that much that we wanted secured. I name the folder the same as the original document, i.e.: /webroot/survey.pdf/ and then placed the index.php inside of the survey.pdf folder.
This worked, and now we can use the script to link to content that we want secured.

Resources