I've created a namespaced route called checkout.
I have the following in router.js.
// router.js
this.route('checkout', function() {
this.resource('payments', function() {
});
});
The following routes can be accessed via:
http://localhost/checkout/payments
However, the controllers, templates, routes for payment, don't exist in the the checkout directory. I would have imagined:
app/controllers/checkout/payments/index.js
app/routes/checkout/payments/index.js
app/templates/checkout/payments/index.hbs
But instead they exist and can be accessed by Ember in:
app/controllers/payments/index.js
app/routes/payments/index.js
app/templates/payments/index.hbs
Is this expected?
That it works at all is partially due to what Asgaroth describes: resources reset the namespace so in your example ember-cli is looking for a class Payments rather than CheckoutPayments, and partially due to ember-cli supporting two directory layouts (the regular one and the "pod" layout). While it builds the application it takes the name of classes from the file or the directory, depending on which is most appropriate.
You are basically mixing and matching the two approaches to the file system layout, which is why it works at all. But it would be incredibly difficult to figure out what belongs to what without a better structure in place.
Instead I'm using the ember generate --pod ... structure with them (which should become recommended for Ember 2.0), which results in a somewhat similar structure for my files as in your question:
app/map
├── debug
│ ├── controller.js
│ ├── route.js
│ └── template.hbs
├── index
│ ├── controller.js
│ └── template.hbs
├── settings
│ ├── controller.js
│ └── template.hbs
├── systems
│ ├── system
│ │ ├── route.js
│ │ └── template.hbs
│ ├── controller.js
│ ├── route.js
│ └── template.hbs
├── controller.js
└── template.hbs
And yes, you can nest routes (since Ember 1.7 or so) and with ES6 modules it brings little benefit to use resources over routes. I've stopped using them, as per the structure above my router.js now is a rather trivial:
this.route( 'map', function() {
this.route( 'systems', function() {
this.route( 'system', { path: ':system_id' } );
});
this.route( 'settings' );
this.route( 'debug' );
});
I can highly recommend the pod structure for your routers, controllers, mixins and components .. it takes some getting used to though, and your editor has to show directory names to be able to know what you are editing.
I don't think you can nest routes within routes are you sure you are not talking about resources?
A resource always resets the namespace.
The route, controller, and view class names for the comments resource
are not prefixed with Post. Resources always reset the namespace,
ensuring that the classes can be re-used between multiple parent
resources and that class names don't get longer the deeper nested the
resources are.
emphasys mine
Related
example app tree:
articles
├── admin.py
├── apps.py
├── models.py
├── static
│ ├── css
│ │ ├── article_change.css
│ │ ├── article_create.css
│ │ ├── article_detail.css
│ └── js (obfuscated)
│ ├── article_create.js
│ ├── article_list.js
│ ├── edit_process.js
│ ├── editor.js
│ └── js (readable)
│ ├── article_create.js
│ ├── article_list.js
│ ├── edit_process.js
│ └── editor.js
├── templates
│ └── articles
│ ├── article_create.html
│ ├── article_detail.html
│ ├── edit_process.html
│ └── editor.html
├── tests.py
├── urls.py
└── views.py
static/js/js contains javascript that is human readable
static/js contains obfuscated javascript files.
I wrote a template tag to includes files:
#register.simple_tag
def jstatic(path):
s = ''
if settings.DEBUG:
s = 'js/'
return static(s + path)
in templates, I can do:
<script src="{% jstatic 'js/info.js' %}"></script>
which conditionally renders static javascript files based on DEBUG mode. whereas, if not in DEBUG mode, will serve obfuscated files.
the thing is, I don't want unobfuscated file to be accessed when DEBUG is not on, which is running the application on server.
when debug is on, I want user user only to visit obfuscated files:
static/js/js/info.js
and have no access to
static/js/info.js
all the apps follows this root tree convention, I wonder if there is a way, for me to block static/js/info.js is DEBUG is not on.
I have thought about shell setting directory permissions, but give up eventually. because, it will not work due to the wrapping structure of the directory. and it will be too much work to modify it, in the project there are about 20 apps.
This is not possible through standard configuration. How to solve this depends on your configuration, but there are three ways to solve this:
If you use some kind of minifier/webpack like configuration to obfuscate your JS files, you could move the JS files to a src directory and have your tooling only copy when DEBUG is True, and copy and obfuscate when debug is False.
You can use two static directories, one for readable files, and the other for obfuscated files (something like src/static/* and dist/static/*), and then only point to the source directory on development environments:
STATICFILES_DIRS = [ "src/static", "dist/static"] vs. STATICFILES_DIRS = [ "dist/static"] on production.
In this case, Django's static files finder will return the first match found.
Leave your configuration as is, but use a webserver like NGINX for serving static files (Which is already the recommended way to serve static files.) In NGINX's configuration you can define a location that 404's as long as it appears before the location serving your static files.
I have already implemented a csv import feature in my app using this plugin, and it works great! But recently I had to reinstall some of my assets and it appears the plugin has some recent additions that include ES15 syntax. My Rails 4 app isn't ready to digest ES15 so I'm looking for a way to exclude the offending files if I can.
The plugin's directory structure looks like this (with some items omitted for brevity).
├── src
│ ├── jquery.csv.js
│ └── jquery.csv.min.js
└── test
├── csv.from_array.js
├── csv.from_arrays.js
├── csv.parsers.js
├── csv.to_array.js
├── etc ...
The ES15 code only appears in the test/ files. In my assets pipeline I include jquery.csv.js, which apparently includes the test/ files, as it's choking on the ES15 when I precompile assets. (If I don't require jquery.csv.js, assets precompile fine.)
This illustrates the errors I'm seeing when I precompile.
Seems like I should be able to do without the test files, but looking in jquery.csv.js it's not obvious to me how they're being included.
I know I should probably focus on getting Rails upgraded or use webpack/babel/whatever to integrate ES15 but I'm hoping for a short-term fix so I can move forward.
Thanks for any tips!
i have a django project and my web static files are at 'web/' directory
here is the structure:
➜ web git:(ycw.alpha) tree -L 4
.
└── forward
├── asserts
│ ├── img
│ │ ├── background
│ │ ├── qr
│ │ └── thumb
│ └── style
│ ├── css
│ └── sass
├── index.html
├── package.json
├── script.js
├── source
└── unit
i have configured Nginx conf and i want nginx to directly indicate to 'web/forward/index.html' when i request my own website 'http://example.com'
i do the thing above like this:
location / {
index index.html
root /path/to/my/django/project/;
}
location /index.html {
alias /path/to/my/django/project/web/forward/index.html;
}
it indeed directly redirects to 'index.html', but the question is there are some references in 'index.html' to some static files such as img or css and the paths are relative paths like './asserts/style/css/index.css' so consequently these files are not found as 404
how can i configure it correctly?
The problem has been solved by changing 'root' in location / to '/path/to/the/index/directory' rather than the root directory of the django project, in this way you can still use relative paths of static resources in html file generally.
I have a React app hosted on an S3 bucket. The code is minified using yarn build (it's a create-react-app based app). The build folder looks something like:
build
├── asset-manifest.json
├── favicon.ico
├── images
│ ├── map-background.png
│ └── robot-icon.svg
├── index.html
├── js
│ ├── fontawesome.js
│ ├── packs
│ │ ├── brands.js
│ │ ├── light.js
│ │ ├── regular.js
│ │ └── solid.js
│ └── README.md
├── service-worker.js
└── static
├── css
│ ├── main.bf27c1d9.css
│ └── main.bf27c1d9.css.map
└── js
├── main.8d11d7ab.js
└── main.8d11d7ab.js.map
I never want index.html to be cached, because if I update the code (causing the hex suffix in main.*.js to update), I need the user's next visit to pick up on the <script src> change in index.html to point to the updated code.
In CloudFront, I can only seem to exclude paths, and excluding "/" doesn't seem to work properly. I'm getting strange behavior where I change the code, and if I hit refresh, I see it, but if I quit Chrome and go back, I see very outdated code for some reason.
I don't want to have to trigger an invalidation on every code release (via CodeBuild). Is there some other way? I think one of the challenges is that since this is an app using React Router, I'm having to do some trickery by setting the error document to index.html and forcing an HTTP status 200 instead of 403.
A solution based on CloudFront configuration:
Go to your CloudFront distribution, under the "Behavior" tab and create a new behavior.
Specify the following values:
Path Pattern: index.html
Object Caching: customize
Maximum TTL: 0 (or another very small value)
Default TTL: 0 (or another very small value)
Save this configuration.
CloudFront will not cache index.html anymore.
If you never want index.html to be cached, set the Cache-Control: max-age=0 header on that file only. CloudFront will make a request back to your origin S3 bucket on every request, but it sounds like this is desired behavior.
If you're wanting to set longer expiry times and invalidate the CloudFront cache manually, you can use a * or /* as your invalidation path (not / as you have mentioned). This can take up to 15 minutes for all CloudFront edge nodes around the world to reflect the changes in your origin however.
Here is the command I ran to set cache-control on my index.html file after uploading new files to s3 and invalidating Cloudfront:
aws s3 cp s3://bucket/index.html s3://bucket/index.html --metadata-directive REPLACE --cache-control max-age=0 --content-type "text/html"
It's much better to run an invalidation for index.html on every release than to defeat Cloudfront's purpose and serve it (what is basically an entrypoint for your app) from S3 every single time.
I've covered some related topic here on stackoverflow and on some another websites, but still I can't decide, how should I organize Django apps?
Before, I used CodeIgniter and I liked it organization structure.
Ok.
The basic structure looks like
testsite/
├── manage.py
│
├── testsite/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
│
└── testapp/
├── __init__.py
├── models.py
├── tests.py
└── views.py
For example, I need model for users and a blog. Do I need write both of it in -testapp/models.py, or it would be better to create different app for blog / users?
You can put it wherever you think it makes the most sense. If you are ONLY going to have one Blog model and no functionality related it it, it could make sense to put it inside of your testapp, but I'm guessing it will have templates associated with it, url paths, views, so I think it should be its own app blog.
The same goes for the user model.
Also make sure you check out djangos built in User model