Changed how domains are handled

This commit is contained in:
Pitu 2017-10-03 19:48:26 -03:00
parent d1260563d4
commit c1963b2809
2 changed files with 62 additions and 60 deletions

View File

@ -11,21 +11,21 @@ module.exports = {
// If true, users will be able to create accounts and access their uploaded files // If true, users will be able to create accounts and access their uploaded files
enableUserAccounts: true, enableUserAccounts: true,
// The registered domain where you will be serving the app. Use IP if none.
domains: [
/* /*
You need to specify the base domain where loli-self is running Here you can decide if you want lolisafe to serve the files or if you prefer doing so via nginx.
and how should it resolve the URL for uploaded files. For example: The main difference between the two is the ease of use and the chance of analytics in the future.
If you set it to `true`, the uploaded files will be located after the host like:
https://lolisafe.moe/yourFile.jpg
If you set it to `false`, you need to specify the domain in the setting right below `serveFilesWithNode`
and make nginx directly serve whatever folder it is you are serving your downloads in. This also gives
you the ability to serve them, for example, like this:
https://files.lolisafe.moe/yourFile.jpg
So ultimately, it's up to you.
*/ */
serveFilesWithNode: false,
// Files will be served at http(s)://i.kanacchi.moe/Fxt0.png domain: '',
{ host: 'kanacchi.moe', resolve: 'https://i.kanacchi.moe'},
// Files will be served at https://my.kanacchi.moe/loli-self/files/Fxt0.png
{ host: 'kanacchi.moe', resolve: 'https://my.kanacchi.moe/loli-self/files' }
],
// Port on which to run the server // Port on which to run the server
port: 9999, port: 9999,
@ -48,18 +48,20 @@ module.exports = {
// Folder where images should be stored // Folder where images should be stored
folder: 'uploads', folder: 'uploads',
// Max file size allowed. Needs to be in MB /*
// Note: When maxSize is greater than 1 MiB, Max file size allowed. Needs to be in MB
// you must set the client_max_body_size Note: When maxSize is greater than 1 MiB, you must set the client_max_body_size to the same as maxSize.
// to the same as maxSize. */
maxSize: '512MB', maxSize: '512MB',
// The length of the random generated name for the uploaded files // The length of the random generated name for the uploaded files
fileLength: 32, fileLength: 32,
// NOTE: Thumbnails are only for the admin panel and they require you /*
// to install a separate binary called graphicsmagick (http://www.graphicsmagick.org) NOTE: Thumbnails are only for the admin panel and they require you
// for images and FFmpeg (https://ffmpeg.org/) for video files to install a separate binary called graphicsmagick (http://www.graphicsmagick.org)
for images and ffmpeg (https://ffmpeg.org/) for video files
*/
generateThumbnails: false generateThumbnails: false
}, },
@ -69,9 +71,7 @@ module.exports = {
// The following values shouldn't be touched // The following values shouldn't be touched
database: { database: {
client: 'sqlite3', client: 'sqlite3',
connection: { connection: { filename: './database/db' },
filename: './database/db'
},
useNullAsDefault: true useNullAsDefault: true
} }
} }

View File

@ -1,55 +1,57 @@
const config = require('./config.js') const config = require('./config.js');
const api = require('./routes/api.js') const api = require('./routes/api.js');
const album = require('./routes/album.js') const album = require('./routes/album.js');
const express = require('express') const express = require('express');
const helmet = require('helmet') const helmet = require('helmet');
const bodyParser = require('body-parser') const bodyParser = require('body-parser');
const RateLimit = require('express-rate-limit') const RateLimit = require('express-rate-limit');
const db = require('knex')(config.database) const db = require('knex')(config.database);
const fs = require('fs') const fs = require('fs');
const exphbs = require('express-handlebars') const exphbs = require('express-handlebars');
const safe = express() const safe = express();
require('./database/db.js')(db) require('./database/db.js')(db)
fs.existsSync('./pages/custom' ) || fs.mkdirSync('./pages/custom') fs.existsSync('./pages/custom' ) || fs.mkdirSync('./pages/custom');
fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder) fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder);
fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder) fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder);
fs.existsSync('./' + config.uploads.folder + '/thumbs') || fs.mkdirSync('./' + config.uploads.folder + '/thumbs') fs.existsSync('./' + config.uploads.folder + '/thumbs') || fs.mkdirSync('./' + config.uploads.folder + '/thumbs');
safe.use(helmet()) safe.use(helmet());
safe.set('trust proxy', 1) safe.set('trust proxy', 1);
safe.engine('handlebars', exphbs({defaultLayout: 'main'})) safe.engine('handlebars', exphbs({ defaultLayout: 'main' }));
safe.set('view engine', 'handlebars') safe.set('view engine', 'handlebars');
safe.enable('view cache') safe.enable('view cache');
let limiter = new RateLimit({ windowMs: 5000, max: 2 }) let limiter = new RateLimit({ windowMs: 5000, max: 2 });
safe.use('/api/login/', limiter) safe.use('/api/login/', limiter);
safe.use('/api/register/', limiter) safe.use('/api/register/', limiter);
safe.use(bodyParser.urlencoded({ extended: true })) safe.use(bodyParser.urlencoded({ extended: true }));
safe.use(bodyParser.json()) safe.use(bodyParser.json());
safe.use('/', express.static('./uploads')) if (config.serveFilesWithNode) {
safe.use('/', express.static('./public')) safe.use('/', express.static('./uploads'));
safe.use('/', album) }
safe.use('/api', api)
safe.use('/', express.static('./public'));
safe.use('/', album);
safe.use('/api', api);
for (let page of config.pages) { for (let page of config.pages) {
let root = './pages/' let root = './pages/';
if (fs.existsSync(`./pages/custom/${page}.html`)) { if (fs.existsSync(`./pages/custom/${page}.html`)) {
root = './pages/custom/' root = './pages/custom/';
} }
if (page === 'home') { if (page === 'home') {
safe.get('/', (req, res, next) => res.sendFile(`${page}.html`, { root: root })) safe.get('/', (req, res, next) => res.sendFile(`${page}.html`, { root: root }));
} else { } else {
safe.get(`/${page}`, (req, res, next) => res.sendFile(`${page}.html`, { root: root })) safe.get(`/${page}`, (req, res, next) => res.sendFile(`${page}.html`, { root: root }));
} }
} }
safe.use((req, res, next) => res.status(404).sendFile('404.html', { root: './pages/error/' })) safe.use((req, res, next) => res.status(404).sendFile('404.html', { root: './pages/error/' }));
safe.use((req, res, next) => res.status(500).sendFile('500.html', { root: './pages/error/' })) safe.use((req, res, next) => res.status(500).sendFile('500.html', { root: './pages/error/' }));
safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`)) safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`));