I have an ember app that is served by Parse hosting, and for the most part it's working great if the user starts at the root URL (for which Parse serves up the public/index.html file). However, if a user loads the page at any path, say, /about, Parse will look for a public/about.html file, which doesn't exist (ember serves everything from the index.html file). Parse throws a 404 for any path but the root. How do I get around this?
I have a mini Express app setup, perhaps I could catch all routes and render the index.html file that's in the public folder? The docs only talk about rendering templates from the cloud/views folder (not the public folder, which is where the index.html file is).
Update / Clarification:
This is not an issue with Ember itself (the app works fine on my local machine). The issue is with Parse. When a URL, parseapp.com/entries, is loaded, parse looks for a file in the cloud/public folder called entries.html. There is no such file, this app is an ember app, and ember is loaded from the index.html file. Thus, for every path, I need parse to load the public/index.html file (and then ember routing will take care of the rest).
Related
I created a login page in Django that has various Javascript and CSS dependencies, which I have placed in the same folder and provided proper script locations. When I test only the page in a browser it seems to load fine with all the files. However, when I send any request and when Django returns the web page using return render(request, 'InsertPage/login.html') only the web page is returned and not the dependent files.
That is normal behavior.
Dependent files are not sent with the response. What happens is that the browser inspects the response, looks for links in the HTML (like images, scripts, stylesheets, etc.), and makes extra requests to fetch these dependencies as well. These dependencies can be located somewhere else (for example a different web server).
You can let Django serve static files in development mode, but it is strongly advised not to use that in production. Then you need to configure the Nginx/Apache/… server such that it serves these files.
I want to do something very simple that I am a little surprised people are not talking about more. I would like to generate on my server my own index.html from the files that are created from building ember for production. I use ember for part of my application and so when a certain URL is hit, I would then like my ember app to take over. I have tried generating my own index.html by changing the flag storeConfigInMeta in ember-cli-build.js.
storeConfigInMeta: false
This gets rid of the ember app having its configuration stored in a meta tag but the app still does not work and gives the error,
Uncaught ReferenceError: define is not defined
I have the latest version of ember and I am building ember with the command,
ember build --env production
My server generated index.html looks identical accept for the integrity attributes set on the include js and css scripts. Is their anything I am missing about approaching ember this way? Should I not be trying to do this?
when a certain URL is hit, I would then like my ember app to take
over.
You need to configure app server to return index.html file for the certain URL.
Generally, it's not required you to create your own index.html.
May be you can check ember-islands addon to include Ember components anywhere on a server-rendered page.
I made a mistake. I was grabbing the production assets with a regular expression with my server and generating my index.html file with these assets in the wrong order. To anyone looking to do this, it is very possible and is more preferable in my opinion to using the generated index.html unless you are using ember for your entire site's routing. However do use the setting in ember-cli-build.js,
storeConfigInMeta: false
This will make it so your ember app stores it's settings in javascript instead of in a tag. This is required for generating your own index.html file.
I am facing problem with static content such as .png, .jpg files in Django+extjs environment.
I develop my client side in Extjs with sencha environment and test it locally with sencha server (sencha app watch) which works fine and I see the static images on the UI page.
Now I take a production build of that app (sencha app build classic).
It generates two folders.
Classic : This has app.js and CSS,fonts etc...
resources : (Here is the problem) This has static files like images and json files(if any)
Now I copy these two folders to my Django static path and access the app.js and and CSS files from Django's HTML template. This works.
However, The problem is Django is unable to locate the image files that are there in resources folder (mentioned in list item 2).
If the URL is 'localhost:81/app_name', it searches for the images in the below path
localhost:81/app_name/resources/images/abc.png
But is should look in the below path to get these files
localhost:81/static/resources/images/abc.png
What am i missing here? How Do I tell Django/Extjs to search for the static content in localhost:81/static/resources/images/abc.png
Please suggest.
I am trying to deploy an Ember-cli app by copying the files generated by ember build into the rails public folder following the approach shown in:
http://blog.abuiles.com/blog/2014/05/21/deploying-ember-cli-and-rails-to-heroku/
https://github.com/dockyard/ember-cli-plus-backend/tree/rails-served-html/frontend/app
But it doesn't seem to work as shown in the app on heroku, rather than display the content, it displays raw json on the web page which suggests the emberjs route model hook is not being called when you enter the app via url. The JSON it displays is something like this:
[{"id":1,"name":"james","presentation_ids":[1,2]},{"id":2,"name":"charle","presentation_ids":[3]}]}
However, if I leave the index.html file generated by ember-build in the rails app/public folder instead of copying the content of the index.html to rails layout/application.html.erb, the content of the ember-cli app's application.hbs will display correctly but if I directly load any route in the browser, it will again return a raw json rather than display the content.
You're routing root requests to speaker#index, which is why you're getting the json response when visiting /.
You want your rails app to serve up index.html on all requests other than /api, something like
get '*path', to: 'index#show'
That action should just serve up your Ember CLI project's static index.html file.
I'd also suggest getting this working locally before messing with Heroku.
I've been developing a site with sensitive (i.e. proprietary) code on my local machine, testing it using apache2, and I'm finally going to be getting it setup with a web host. I'm a bit wary because of the "Where should this code live?" note here in the Django Tutorial:
Where should this code live?
If your background is in plain old PHP (with no use of modern frameworks), you’re probably used to putting code under the Web server’s document root (in a place such as /var/www). With Django, you don’t do that. It’s not a good idea to put any of this Python code within your Web server’s document root, because it risks the possibility that people may be able to view your code over the Web. That’s not good for security.
Put your code in some directory outside of the document root, such as /home/mycode.
My host told me that I'll be given a /home/ directory, and that the site will live in /home/www. I'm trying to emulate this directory structure on my end before I send everything to him to make sure it goes as smoothly as possible. My question is, if I want all my code to live outside of the /www directory (per the Django tutorial recommendation above), what actually goes inside the /www directory?
My development directory structure is basically this:
project
db
app1
app2
mysite (contains settings.py, wsgi.py, etc.)
static
templates (contains my base.html, and custom templates for admin, etc.)
Where app1 and app2 are Django apps I've developed to plug into mysite. So what folders / files need to go in the home/www directory, and what can safely live in home/mycode?
Your static and media (user-uploaded) folders, robots.txt etc. should be in the www directory. Basically any file that is directly served by your webserver and not through Django. Other files should live outside of this directory.
Your webserver should point all requests that are not found in the www directory towards your wsgi application, which doesn't need the code to be accessible by an url.
The reason for this is that your webserver does not execute the code in a python file, in contrast to php files. If your code lived in your web root, people could read your settings files by just going to example.com/src/settings.py. Images, plain html/text files and javascript should be read, but any code that should be executed should live outside your web root. Django will execute the files and generate the response that a user should actually see.