Browse Source

Added multi-domain support. Maybe

Pitu 7 years ago
parent
commit
aae56e91c9
3 changed files with 15 additions and 10 deletions
  1. 7 4
      config.sample.js
  2. 7 1
      controllers/uploadController.js
  3. 1 5
      lolisafe.js

+ 7 - 4
config.sample.js

@@ -12,11 +12,14 @@ module.exports = {
 	// The registered domain where you will be serving the app. Use IP if none.
 	domains: [
 
-		// Files will be served at https://i.kanacchi.moe/file.png
-		{ base: 'https://i.kanacchi.moe/', prefix: ''},
+		// Files will be served at http(s)://i.kanacchi.moe/Fxt0.png
+		{ host: 'i.kanacchi.moe' },
 
-		// Files will be served at http://localhost:9999/files/file.png
-		{ base: 'http://127.0.0.1:9999/', prefix: 'files/'}
+		// Files will be served at http(s)://my.kanacchi.moe/loli-self/files/Fxt0.png
+		{ host: 'my.kanacchi.moe', resolve: 'https://my.kanacchi.moe/loli-self/files' },
+
+		// Files will be served at http://localhost:9999/Fxt0.png
+		{ domain: 'localhost:9999' }
 	],
 
 	// Port on which to run the server

+ 7 - 1
controllers/uploadController.js

@@ -56,13 +56,19 @@ uploadsController.upload = function(req, res, next){
 
 		db.table('files').insert(files).then(() => {
 			
+			let basedomain = req.get('host') + '/'
+			for(let domain of config.domains)
+				if(domain.host === req.get('host'))
+					if(domain.hasOwnProperty('resolve'))
+						return basedomain = domain.resolve + '/'
+
 			res.json({
 				success: true,
 				files: files.map(file => {
 					return {
 						name: file.name,
 						size: file.size,
-						url: config.basedomain + file.name
+						url: basedomain + file.name
 					}
 				})
 			})

+ 1 - 5
lolisafe.js

@@ -12,11 +12,7 @@ fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder
 
 safe.enable('trust proxy')
 
-let prefix = config.uploads.prefix
-if( prefix !== '' )
-	prefix = prefix + '/'
-
-safe.use('/' + prefix, express.static('./uploads'))
+safe.use('/', express.static('./uploads'))
 safe.use('/', express.static('./public'))
 safe.use('/api', api)