split files into client/ and server/
This commit is contained in:
parent
1ad71585c4
commit
e487adcc97
72 changed files with 55 additions and 46 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,5 +1,2 @@
|
||||||
config.ini
|
config.ini
|
||||||
node_modules
|
*/*_modules/
|
||||||
|
|
||||||
# name used in INSTALL.md
|
|
||||||
python_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:
|
Installing frontend dependencies:
|
||||||
|
|
||||||
```console
|
```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
|
`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:
|
this:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
user@host:path/to/szurubooru$ virtualenv python_modules # consistent with node_modules
|
user@host:szuru/client$ cd ../server
|
||||||
user@host:path/to/szurubooru$ source python_modules/bin/activate # enters the sandbox
|
user@host:szuru/server$ virtualenv python_modules # consistent with node_modules
|
||||||
(python_modules) user@host:path/to/szurubooru$ pip install -r requirements.txt # installs the dependencies
|
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
|
### Preparing `szurubooru` for first run
|
||||||
|
|
||||||
Configure things:
|
1. Configure things:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
user@host:path/to/szurubooru$ cp config.ini.dist config.ini
|
user@host:szuru$ cp config.ini.dist config.ini
|
||||||
user@host:path/to/szurubooru$ vim config.ini
|
user@host:szuru$ vim config.ini
|
||||||
```
|
```
|
||||||
|
|
||||||
Pay extra attention to the `[database]` and `[smtp]` sections, and API URL in
|
Pay extra attention to the `[database]` and `[smtp]` sections, and API URL in
|
||||||
`[basic]`.
|
`[basic]`.
|
||||||
|
|
||||||
Then update the database and compile the frontend:
|
2. Compile the frontend:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
user@host:path/to/szurubooru$ npm run build # compiles frontend
|
user@host:szuru$ cd client
|
||||||
user@host:path/to/szurubooru$ source python_modules/bin/activate # enters python sandbox
|
user@host:szuru/client$ npm run build
|
||||||
(python_modules) user@host:path/to/szurubooru$ alembic update head # runs all DB upgrades
|
```
|
||||||
```
|
|
||||||
|
|
||||||
`alembic` should have been installed during installation of `szurubooru`'s
|
3. Upgrade the database:
|
||||||
dependencies.
|
|
||||||
|
```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.
|
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
|
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`
|
approach, the user needs to (from within `virtualenv`) install `waitress`
|
||||||
with `pip install waitress` and then start `szurubooru` with
|
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,
|
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`.
|
2. Alternatively, Apache users can use `mod_wsgi`.
|
||||||
3. Alternatively, users can use other WSGI frontends such as `gunicorn` or
|
3. Alternatively, users can use other WSGI frontends such as `gunicorn` or
|
||||||
`uwsgi`, but they'll need to write wrapper scripts themselves.
|
`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;
|
proxy_pass http://127.0.0.1:6666/$1$is_args$args;
|
||||||
}
|
}
|
||||||
location / {
|
location / {
|
||||||
root /home/rr-/src/maintained/szurubooru/public;
|
root /home/rr-/src/maintained/szurubooru/client/public;
|
||||||
try_files $uri /index.htm;
|
try_files $uri /index.htm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,5 +155,5 @@ server {
|
||||||
api_url = http://big.dude/api/
|
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`.
|
`virtualenv`.
|
||||||
|
|
|
@ -25,10 +25,10 @@ function getConfig() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = parseIniFile('./config.ini.dist');
|
let config = parseIniFile('../config.ini.dist');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const localConfig = parseIniFile('./config.ini');
|
const localConfig = parseIniFile('../config.ini');
|
||||||
config = merge.recursive(config, localConfig);
|
config = merge.recursive(config, localConfig);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Local config does not exist, ignoring');
|
console.warn('Local config does not exist, ignoring');
|
||||||
|
@ -49,8 +49,8 @@ function getConfig() {
|
||||||
|
|
||||||
function bundleHtml(config) {
|
function bundleHtml(config) {
|
||||||
const minify = require('html-minifier').minify;
|
const minify = require('html-minifier').minify;
|
||||||
const baseHtml = fs.readFileSync('./static/html/index.htm', 'utf-8');
|
const baseHtml = fs.readFileSync('./html/index.htm', 'utf-8');
|
||||||
glob('static/html/**/*.hbs', {}, (er, files) => {
|
glob('./html/**/*.hbs', {}, (er, files) => {
|
||||||
let templatesHtml = '';
|
let templatesHtml = '';
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
templatesHtml += util.format(
|
templatesHtml += util.format(
|
||||||
|
@ -78,7 +78,7 @@ function bundleHtml(config) {
|
||||||
|
|
||||||
function bundleCss() {
|
function bundleCss() {
|
||||||
const minify = require('csso').minify;
|
const minify = require('csso').minify;
|
||||||
glob('static/css/**/*.css', {}, (er, files) => {
|
glob('./css/**/*.css', {}, (er, files) => {
|
||||||
let css = '';
|
let css = '';
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
css += fs.readFileSync(file);
|
css += fs.readFileSync(file);
|
||||||
|
@ -91,7 +91,7 @@ function bundleCss() {
|
||||||
function bundleJs() {
|
function bundleJs() {
|
||||||
const browserify = require('browserify');
|
const browserify = require('browserify');
|
||||||
const uglifyjs = require('uglify-js');
|
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');
|
const outputFile = fs.createWriteStream('./public/bundle.min.js');
|
||||||
browserify().add(files).bundle().pipe(outputFile);
|
browserify().add(files).bundle().pipe(outputFile);
|
||||||
outputFile.on('finish', function() {
|
outputFile.on('finish', function() {
|
||||||
|
@ -104,7 +104,7 @@ function bundleJs() {
|
||||||
|
|
||||||
function bundleConfig(config) {
|
function bundleConfig(config) {
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
'./static/js/.config.autogen.json', JSON.stringify(config));
|
'./js/.config.autogen.json', JSON.stringify(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyFile(source, target) {
|
function copyFile(source, target) {
|
||||||
|
@ -116,4 +116,4 @@ bundleConfig(config);
|
||||||
bundleHtml(config);
|
bundleHtml(config);
|
||||||
bundleCss();
|
bundleCss();
|
||||||
bundleJs();
|
bundleJs();
|
||||||
copyFile('static/favicon.png', 'public/favicon.png');
|
copyFile('./img/favicon.png', './public/favicon.png');
|
Before Width: | Height: | Size: 2 KiB After Width: | Height: | Size: 2 KiB |
0
static/js/.gitignore → client/js/.gitignore
vendored
0
static/js/.gitignore → client/js/.gitignore
vendored
|
@ -2,8 +2,8 @@
|
||||||
"name": "szurubooru",
|
"name": "szurubooru",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node scripts/build-frontend.js",
|
"build": "node build.js",
|
||||||
"watch": "watch 'npm run build' static --wait=0 --ignoreDotFiles"
|
"watch": "watch 'npm run build' html js css img --wait=0 --ignoreDotFiles"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"browserify": "^13.0.0",
|
"browserify": "^13.0.0",
|
0
public/.gitignore → client/public/.gitignore
vendored
0
public/.gitignore → client/public/.gitignore
vendored
|
@ -10,17 +10,13 @@ import argparse
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
import waitress
|
import waitress
|
||||||
|
|
||||||
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.path.pardir))
|
|
||||||
from szurubooru.app import create_app
|
from szurubooru.app import create_app
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser('Starts szurubooru using waitress.')
|
parser = argparse.ArgumentParser('Starts szurubooru using waitress.')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-p', '--port',
|
'-p', '--port', type=int, help='port to listen on', default=6666)
|
||||||
type=int, help='port to listen on', default=6666)
|
parser.add_argument('--host', help='IP to listen on', default='0.0.0.0')
|
||||||
parser.add_argument(
|
|
||||||
'--host', help='IP to listen on', default='0.0.0.0')
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
app = create_app()
|
app = create_app()
|
|
@ -10,8 +10,8 @@ class ConfigurationError(RuntimeError):
|
||||||
class Config(object):
|
class Config(object):
|
||||||
''' INI config parser and container. '''
|
''' INI config parser and container. '''
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = configobj.ConfigObj('config.ini.dist')
|
self.config = configobj.ConfigObj('../config.ini.dist')
|
||||||
if os.path.exists('config.ini'):
|
if os.path.exists('../config.ini'):
|
||||||
self.config.merge(configobj.ConfigObj('config.ini'))
|
self.config.merge(configobj.ConfigObj('config.ini'))
|
||||||
self._validate()
|
self._validate()
|
||||||
|
|
Loading…
Reference in a new issue