I am, mostly for learning purposes, building a very simple RESTful API for serving a random image or a specific image given an ID. This API will be accessed via a AngularJS client (probably) and will be deployed, together with the API, to my web server. The API and the web client will reside in the same project, that is the same root folder which will actually be a subdirectory on my server accessible via http://foo.com/bar and in the same git repository. Maybe I'll create an Android client later on accessing the same API.
However, I have trouble getting the .htaccess routing/rewriting right. Below follows my proposed directory structure.
root/
|-- bar/
| |-- api/
| | |-- v1/
| | | |-- lib/
| | | | `-- ImageFactory.php
| | | |-- vendor/
| | | | `-- slim/
| | | |-- .htaccess (#1)
| | | |-- composer.json
| | | `-- index.php
| |-- public_html/
| | |-- css/
| | |-- img/
| | | `-- bar/
| | |-- js/
| | | |-- controllers/
| | | |-- directives/
| | | |-- filters/
| | | |-- lib/
| | | |-- services/
| | | |-- vendor/
| | | `-- app.js
| | |-- views/
| | |-- api.php
| | `-- index.html
| `-- .htaccess (#2)
I am thinking that each major rework of the API needs a new version which depends on its own version of Slim, should I change the version over the years.
But what about the .htaccess files? I think that calls to http://foo.com/bar should redirect to public_html/index.html, in other words the JS client app. However, calls to http://foo.com/bar/api/v1 should redirect to public_html/api.php and give the version v1 as a parameter so that api.php can load the correct API app.
How should I write my RewriteEngine rules for .htaccess #1 and #2? Is there something off with my proposed structure? Have I missed something? Please help a developer in need!
To achieve what you want, you only need to add some rules in your /root/bar/.htaccess file.
If by redirect you mean internal rewrite (forward to page without changing url in browser) then you can put this code into your htaccess
RewriteEngine On
RewriteBase /bar/
RewriteRule ^$ public_html/index.html [L]
RewriteRule ^api/v([1-9][0-9]*)$ public_html/api.php?version=$1 [L]
Related
I am starting to write a crate for a specific API. I have read the Modules section of The Rust Reference but I'm unclear if the following 2 file structures are equivalent, and is there a preferable/idiomatic approach?
some-crate/
|- src/
| |- bits.rs
| |- bobs.rs
| |- lib.rs
|- foo/
| |- mod.rs
|- bar/
| |- mod.rs
or
some-crate/
|- src/
| |- bits.rs
| |- bobs.rs
| |- lib.rs
| |- foo.rs
| |- bar.rs
I would like to access my sub-level functions with the following notation some-crate::foo::do_this();
The sub-level modules would require access to common items in bits.rs and bobs.rs.
There will be 4 sub-level modules so not a large file structure to manage.
foo/ and bar/ should be inside of src/. The two options are:
some-crate/ some-crate/
|- src/ |- src/
| |- bar/ | |- bar.rs
| | |- mod.rs | |- bits.rs
| |- foo/ | |- bobs.rs
| | |- mod.rs | |- foo.rs
| |- bits.rs | |- lib.rs
| |- bobs.rs |- Cargo.toml
| |- lib.rs
|- Cargo.toml
Which to use is a matter of taste.
Personally, I use mod.rs once a module gets sub-modules because otherwise foo.rs and foo/ end up visually separated since file viewers usually sort directories before files (see example on right):
some-crate/ some-crate/
|- src/ |- src/
| |- bar/ | |- bar/
| | |- mod.rs | | |- baz.rs
| | |- baz.rs | |- foo/
| |- foo/ | | |- quux.rs
| | |- mod.rs | |- bar.rs
| | |- quux.rs | |- bits.rs
| |- bits.rs | |- bobs.rs
| |- bobs.rs | |- foo.rs
| |- lib.rs | |- lib.rs
|- Cargo.toml |- Cargo.toml
In your first example, foo and bar are not part of your crate at all, since they aren't in the src directory. You may have meant to write it this way:
some-crate/
|- src/
| |- bits.rs
| |- bobs.rs
| |- lib.rs
| |- foo/
| |- mod.rs
| |- bar/
| |- mod.rs
This example and your second example are both equivalent, and I would argue the second way is better if you have small, related modules, and this way would be better if there was more of a logical distinction between them (my brain likes visual separation). If foo and bar eventually had sub-modules themselves, however, then using nested directories would be much preferable to nested mod blocks within a single file.
In your lib.rs, you can also use pub use and pub mod to change how your modules are accessed by others (to a certain extent).
Write two command lines needed to create the following directory tree.
~
|-- bigboy/
| `-- opss/
| |-- user
| `-- teacher
|
`-- arch/
|-- b/
| `-- pr.txt
|
`-- 2022F
Using absolute paths, write one command line to copy directory opss with its files to
directory 2022F. How do you prove this has been done? Use a second command line and its output to show this has been done as expected.
I encountered a folder structure at raymii.org/s/tutorials and I'm not really sure what the symbols `-- mean. Couln't also find any syntax or documentation on how to write such structures.
$ tree -L 2 ExampleProject/
ExampleProject/
|-- build/
|-- CMakeLists.txt
|-- lib/
| `-- googletest
|-- src/
| |-- CMakeLists.txt
| |-- Formula.cpp
| |-- Formula.h
| `-- main.cpp
`-- tst/
|-- CMakeLists.txt
|-- Formula-test.cpp
`-- main.cpp
The symbols represent a polygonal chain leading from the parent directory to the file. '-' represents a horizontal segment of the chain, '`' represents a diagonal segment and '|' represents a vertical segment.
The chain conveys the parent-child relationship of a directory entry and the directory that contains it.
This particular tree shows the root directory ExampleProject which contains a sub directory src which contains a file CMakeLists.txt. And a bunch of other directories and files.
I can't understand why I have different total size in a folder versus in parent.
That's my folder tree
bkp
|-- raid10
| |-- folder_a
| |-- folder_b
| |-- folder_c
| |-- folder_d
| |-- folder_e
| |-- folder_f
| |-- folder_g
| |-- folder_h
| |-- folder_i
| |-- folder_j
| |-- folder_k
| |-- folder_l
| |-- script.sh
|-- vm
I previously delete a big amount of file in that folder and I want to get my new disk usage.
sudo du -shc /bkp/*
756G raid10
4.0K vm
756G total
Now I execute that command to get more info about the folder raid10:
sudo du -shc /bkp/raid10/*
13G folder_a
178M folder_b
15G folder_c
2.3G folder_d
32M folder_e
31G folder_f
31G folder_g
49G folder_h
131M folder_i
4.7G folder_j
392M folder_k
4.0K folder_l
4.0K lost+found
4.0K script.sh~
144G total
Why the total is so different ?
I checked man du and tried some command, like --apparent-size, but same result. Also try without -s sudo du -hc /bkp/raid10/*, I have the same total but I see all directory...
I have some assumptions:
There is some cache in du command ?
There is a trash or hidden file that du can't read?
Some information about my files:
Disk filesystem is ext4
File are uploaded with rsync
Disk is not in raid
To make du search for invisible just do:
#First part will get all invisible and second will get all non-invisible
du -shc /bkp/raid10/.[!.]* /bkp/raid10/*
Or cleaner command:
cd /bkp/raid10
du -sch .[!.]* *
Or enable shell option that matches hidden file with globbing
shopt -s dotglob
du -sch *
To look for hidden (names starting with a dot) files/directories recursively:
find . -name ".*" -ls
In linux or freebsd, Is there a way to copy all files under a folder and its subfolders as symbolic link ? I need to copy thousands of files into different locations as symbolic links and only have 2-3 configuration files as the actual file. The reason I'm doing this is, I have dozen of websites with with exactly the same engine code, but different configuration and look. I want to copy the engine as symbolic link so every change I make to original files will be applied to other websites as well.
I can't make symbolic link to the engine folder itself, because the configuration file is under that folder, and I can't copy files one by one ! cause obviously it's not practical.
Any suggestion ?
The command you are looking for is cp -rs /path/to/source dest.
Note that you need to provide full path to the source directory so that it can make absolute symlinks.
i don't know if this is what you want: (see example below)
dir one is your central "engine"
dir two is one of your website.
kent#ArchT60:/tmp$ tree one two
one
|-- 1.txt
|-- 2.txt
|-- 3.txt
|-- 4.txt
|-- 5.txt
|-- dirA
| |-- a
| |-- b
| `-- c
|-- dirB
`-- dirC
two
|-- myConf_a.conf
|-- myConf_b.conf
|-- myConf_c.conf
|-- myConf_d.conf
`-- myConf_e.conf
kent#ArchT60:/tmp$ ln -s /tmp/one/* /tmp/two/.
kent$ tree -l /tmp/two
/tmp/two
|-- 1.txt -> /tmp/one/1.txt
|-- 2.txt -> /tmp/one/2.txt
|-- 3.txt -> /tmp/one/3.txt
|-- 4.txt -> /tmp/one/4.txt
|-- 5.txt -> /tmp/one/5.txt
|-- dirA -> /tmp/one/dirA
| |-- a
| |-- b
| `-- c
|-- dirB -> /tmp/one/dirB
|-- dirC -> /tmp/one/dirC
|-- myConf_a.conf
|-- myConf_b.conf
|-- myConf_c.conf
|-- myConf_d.conf
`-- myConf_e.conf