split files into client/ and server/
This commit is contained in:
		
							parent
							
								
									1ad71585c4
								
							
						
					
					
						commit
						e487adcc97
					
				
							
								
								
									
										5
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1,5 +1,2 @@ | ||||
| config.ini | ||||
| node_modules | ||||
| 
 | ||||
| # name used in INSTALL.md | ||||
| python_modules | ||||
| */*_modules/ | ||||
|  | ||||
							
								
								
									
										64
									
								
								INSTALL.md
									
									
									
									
									
								
							
							
						
						
									
										64
									
								
								INSTALL.md
									
									
									
									
									
								
							| @ -39,12 +39,20 @@ user@host:~$ sudo -i -u postgres psql -c "ALTER USER szuru PASSWORD 'dog';" | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| ### Installing soft dependencies | ||||
| ### Preparing environment | ||||
| 
 | ||||
| Getting `szurubooru`: | ||||
| 
 | ||||
| ```console | ||||
| user@host:~$ git clone https://github.com/rr-/szurubooru2 szuru | ||||
| user@host:~$ cd szuru | ||||
| ``` | ||||
| 
 | ||||
| Installing frontend dependencies: | ||||
| 
 | ||||
| ```console | ||||
| user@host:path/to/szurubooru$ npm install | ||||
| user@host:szuru$ cd client | ||||
| user@host:szuru/client$ npm install | ||||
| ``` | ||||
| 
 | ||||
| `npm` sandboxes dependencies by default, i.e. installs them to | ||||
| @ -54,35 +62,43 @@ project's dependencies. To make Python work the same way, we'll use | ||||
| this: | ||||
| 
 | ||||
| ```console | ||||
| user@host:path/to/szurubooru$ virtualenv python_modules # consistent with node_modules | ||||
| user@host:path/to/szurubooru$ source python_modules/bin/activate # enters the sandbox | ||||
| (python_modules) user@host:path/to/szurubooru$ pip install -r requirements.txt # installs the dependencies | ||||
| user@host:szuru/client$ cd ../server | ||||
| user@host:szuru/server$ virtualenv python_modules # consistent with node_modules | ||||
| user@host:szuru/server$ source python_modules/bin/activate # enters the sandbox | ||||
| (python_modules) user@host:szuru/server$ pip install -r requirements.txt # installs the dependencies | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| ### Preparing `szurubooru` for first run | ||||
| 
 | ||||
| Configure things: | ||||
| 1. Configure things: | ||||
| 
 | ||||
| ```console | ||||
| user@host:path/to/szurubooru$ cp config.ini.dist config.ini | ||||
| user@host:path/to/szurubooru$ vim config.ini | ||||
| ``` | ||||
|     ```console | ||||
|     user@host:szuru$ cp config.ini.dist config.ini | ||||
|     user@host:szuru$ vim config.ini | ||||
|     ``` | ||||
| 
 | ||||
| Pay extra attention to the `[database]` and `[smtp]` sections, and API URL in | ||||
| `[basic]`. | ||||
|     Pay extra attention to the `[database]` and `[smtp]` sections, and API URL in | ||||
|     `[basic]`. | ||||
| 
 | ||||
| Then update the database and compile the frontend: | ||||
| 2. Compile the frontend: | ||||
| 
 | ||||
| ```console | ||||
| user@host:path/to/szurubooru$ npm run build # compiles frontend | ||||
| user@host:path/to/szurubooru$ source python_modules/bin/activate # enters python sandbox | ||||
| (python_modules) user@host:path/to/szurubooru$ alembic update head # runs all DB upgrades | ||||
| ``` | ||||
|     ```console | ||||
|     user@host:szuru$ cd client | ||||
|     user@host:szuru/client$ npm run build | ||||
|     ``` | ||||
| 
 | ||||
| `alembic` should have been installed during installation of `szurubooru`'s | ||||
| dependencies. | ||||
| 3. Upgrade the database: | ||||
| 
 | ||||
|     ```console | ||||
|     user@host:szuru/client$ cd ../server | ||||
|     user@host:szuru/server$ source python_modules/bin/activate | ||||
|     (python_modules) user@host:szuru/server$ alembic update head | ||||
|     ``` | ||||
| 
 | ||||
|     `alembic` should have been installed during installation of `szurubooru`'s | ||||
|     dependencies. | ||||
| 
 | ||||
| It is recommended to rebuild the frontend after each change to configuration. | ||||
| 
 | ||||
| @ -99,9 +115,9 @@ Below are described the methods to integrate the API into a web server: | ||||
| 1. Run API locally with `waitress`, and bind it with a reverse proxy. In this | ||||
|    approach, the user needs to (from within `virtualenv`) install `waitress` | ||||
|    with `pip install waitress` and then start `szurubooru` with | ||||
|    `./scripts/host-waitress` (see `--help` for details). Then the user needs to | ||||
|    `./server/host-waitress` (see `--help` for details). Then the user needs to | ||||
|    add a virtual host that delegates the API requests to the local API server, | ||||
|    and the browser requests to the `public/` directory. | ||||
|    and the browser requests to the `client/public/` directory. | ||||
| 2. Alternatively, Apache users can use `mod_wsgi`. | ||||
| 3. Alternatively, users can use other WSGI frontends such as `gunicorn` or | ||||
|    `uwsgi`, but they'll need to write wrapper scripts themselves. | ||||
| @ -126,7 +142,7 @@ server { | ||||
|         proxy_pass http://127.0.0.1:6666/$1$is_args$args; | ||||
|     } | ||||
|     location / { | ||||
|         root /home/rr-/src/maintained/szurubooru/public; | ||||
|         root /home/rr-/src/maintained/szurubooru/client/public; | ||||
|         try_files $uri /index.htm; | ||||
|     } | ||||
| } | ||||
| @ -139,5 +155,5 @@ server { | ||||
| api_url = http://big.dude/api/ | ||||
| ``` | ||||
| 
 | ||||
| Then the backend is started with `./scripts/host-waitress` from within | ||||
| Then the backend is started with `./server/host-waitress` from within | ||||
| `virtualenv`. | ||||
|  | ||||
| @ -25,10 +25,10 @@ function getConfig() { | ||||
|         return result; | ||||
|     } | ||||
| 
 | ||||
|     let config = parseIniFile('./config.ini.dist'); | ||||
|     let config = parseIniFile('../config.ini.dist'); | ||||
| 
 | ||||
|     try { | ||||
|         const localConfig = parseIniFile('./config.ini'); | ||||
|         const localConfig = parseIniFile('../config.ini'); | ||||
|         config = merge.recursive(config, localConfig); | ||||
|     } catch (e) { | ||||
|         console.warn('Local config does not exist, ignoring'); | ||||
| @ -49,8 +49,8 @@ function getConfig() { | ||||
| 
 | ||||
| function bundleHtml(config) { | ||||
|     const minify = require('html-minifier').minify; | ||||
|     const baseHtml = fs.readFileSync('./static/html/index.htm', 'utf-8'); | ||||
|     glob('static/html/**/*.hbs', {}, (er, files) => { | ||||
|     const baseHtml = fs.readFileSync('./html/index.htm', 'utf-8'); | ||||
|     glob('./html/**/*.hbs', {}, (er, files) => { | ||||
|         let templatesHtml = ''; | ||||
|         for (const file of files) { | ||||
|             templatesHtml += util.format( | ||||
| @ -78,7 +78,7 @@ function bundleHtml(config) { | ||||
| 
 | ||||
| function bundleCss() { | ||||
|     const minify = require('csso').minify; | ||||
|     glob('static/css/**/*.css', {}, (er, files) => { | ||||
|     glob('./css/**/*.css', {}, (er, files) => { | ||||
|         let css = ''; | ||||
|         for (const file of files) { | ||||
|             css += fs.readFileSync(file); | ||||
| @ -91,7 +91,7 @@ function bundleCss() { | ||||
| function bundleJs() { | ||||
|     const browserify = require('browserify'); | ||||
|     const uglifyjs = require('uglify-js'); | ||||
|     glob('./static/js/**/*.js', {}, function(er, files) { | ||||
|     glob('./js/**/*.js', {}, function(er, files) { | ||||
|         const outputFile = fs.createWriteStream('./public/bundle.min.js'); | ||||
|         browserify().add(files).bundle().pipe(outputFile); | ||||
|         outputFile.on('finish', function() { | ||||
| @ -104,7 +104,7 @@ function bundleJs() { | ||||
| 
 | ||||
| function bundleConfig(config) { | ||||
|     fs.writeFileSync( | ||||
|         './static/js/.config.autogen.json', JSON.stringify(config)); | ||||
|         './js/.config.autogen.json', JSON.stringify(config)); | ||||
| } | ||||
| 
 | ||||
| function copyFile(source, target) { | ||||
| @ -116,4 +116,4 @@ bundleConfig(config); | ||||
| bundleHtml(config); | ||||
| bundleCss(); | ||||
| bundleJs(); | ||||
| copyFile('static/favicon.png', 'public/favicon.png'); | ||||
| copyFile('./img/favicon.png', './public/favicon.png'); | ||||
| Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB | 
| @ -2,8 +2,8 @@ | ||||
|   "name": "szurubooru", | ||||
|   "private": true, | ||||
|   "scripts": { | ||||
|     "build": "node scripts/build-frontend.js", | ||||
|     "watch": "watch 'npm run build' static --wait=0 --ignoreDotFiles" | ||||
|     "build": "node build.js", | ||||
|     "watch": "watch 'npm run build' html js css img --wait=0 --ignoreDotFiles" | ||||
|   }, | ||||
|   "dependencies": { | ||||
|     "browserify": "^13.0.0", | ||||
| @ -10,17 +10,13 @@ import argparse | ||||
| import os.path | ||||
| import sys | ||||
| import waitress | ||||
| 
 | ||||
| sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.path.pardir)) | ||||
| from szurubooru.app import create_app | ||||
| 
 | ||||
| def main(): | ||||
|     parser = argparse.ArgumentParser('Starts szurubooru using waitress.') | ||||
|     parser.add_argument( | ||||
|         '-p', '--port', | ||||
|         type=int, help='port to listen on', default=6666) | ||||
|     parser.add_argument( | ||||
|         '--host', help='IP to listen on', default='0.0.0.0') | ||||
|         '-p', '--port', type=int, help='port to listen on', default=6666) | ||||
|     parser.add_argument('--host', help='IP to listen on', default='0.0.0.0') | ||||
|     args = parser.parse_args() | ||||
| 
 | ||||
|     app = create_app() | ||||
| @ -10,8 +10,8 @@ class ConfigurationError(RuntimeError): | ||||
| class Config(object): | ||||
|     ''' INI config parser and container. ''' | ||||
|     def __init__(self): | ||||
|         self.config = configobj.ConfigObj('config.ini.dist') | ||||
|         if os.path.exists('config.ini'): | ||||
|         self.config = configobj.ConfigObj('../config.ini.dist') | ||||
|         if os.path.exists('../config.ini'): | ||||
|             self.config.merge(configobj.ConfigObj('config.ini')) | ||||
|         self._validate() | ||||
| 
 | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 rr-
						rr-