added config var for public static folder
This commit is contained in:
parent
506c99666e
commit
3a80c4fd3b
4 changed files with 3417 additions and 3601 deletions
|
@ -31,11 +31,12 @@ function SiteConfig () {
|
||||||
thumbnailChannelId : 'default',
|
thumbnailChannelId : 'default',
|
||||||
uploadDirectory : '/home/lbry/Uploads',
|
uploadDirectory : '/home/lbry/Uploads',
|
||||||
};
|
};
|
||||||
|
this.routes = {};
|
||||||
this.update = (config) => {
|
this.update = (config) => {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
return console.log('No site config received.');
|
return console.log('No site config received.');
|
||||||
}
|
}
|
||||||
const { analytics, assetDefaults, auth, customComponents, details, publishing } = config;
|
const { analytics, assetDefaults, auth, customComponents, details, publishing, routes } = config;
|
||||||
console.log('Configuring site details...');
|
console.log('Configuring site details...');
|
||||||
this.analytics = analytics;
|
this.analytics = analytics;
|
||||||
this.assetDefaults = assetDefaults;
|
this.assetDefaults = assetDefaults;
|
||||||
|
@ -43,6 +44,7 @@ function SiteConfig () {
|
||||||
this.details = details;
|
this.details = details;
|
||||||
this.publishing = publishing;
|
this.publishing = publishing;
|
||||||
this.customComponents = customComponents;
|
this.customComponents = customComponents;
|
||||||
|
this.routes = routes;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
2652
index.js
2652
index.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -8,7 +8,7 @@ const cookieSession = require('cookie-session');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const requestLogger = require('middleware/requestLogger.js');
|
const requestLogger = require('middleware/requestLogger.js');
|
||||||
|
const Path = require('path');
|
||||||
const loggerConfig = require('loggerConfig.js');
|
const loggerConfig = require('loggerConfig.js');
|
||||||
const mysqlConfig = require('mysqlConfig.js');
|
const mysqlConfig = require('mysqlConfig.js');
|
||||||
const siteConfig = require('siteConfig.js');
|
const siteConfig = require('siteConfig.js');
|
||||||
|
@ -43,12 +43,24 @@ function Server () {
|
||||||
// trust the proxy to get ip address for us
|
// trust the proxy to get ip address for us
|
||||||
app.enable('trust proxy');
|
app.enable('trust proxy');
|
||||||
|
|
||||||
// add middleware
|
/* add middleware */
|
||||||
app.use(helmet()); // set HTTP headers to protect against well-known web vulnerabilties
|
// set HTTP headers to protect against well-known web vulnerabilties
|
||||||
app.use(express.static(`${__dirname}/public`)); // 'express.static' to serve static files from public directory
|
app.use(helmet());
|
||||||
// note: take in a different public folder, so it can serve it's own bundle from there?
|
// 'express.static' to serve static files from public directory
|
||||||
app.use(bodyParser.json()); // 'body parser' for parsing application/json
|
if (siteConfig.routes.public) {
|
||||||
app.use(bodyParser.urlencoded({ extended: true })); // 'body parser' for parsing application/x-www-form-urlencoded
|
// take in a different public folder, so it can serve it's own bundle if needed
|
||||||
|
const { publicFolder } = siteConfig.routes;
|
||||||
|
app.use(express.static(publicFolder))
|
||||||
|
logger.info('serving static files from custom path:', publicFolder);
|
||||||
|
} else {
|
||||||
|
const publicPath = Path.resolve(__dirname, 'public');
|
||||||
|
app.use(express.static(publicPath));
|
||||||
|
logger.info('serving static files from default path:', publicPath);
|
||||||
|
};
|
||||||
|
// 'body parser' for parsing application/json
|
||||||
|
app.use(bodyParser.json());
|
||||||
|
// 'body parser' for parsing application/x-www-form-urlencoded
|
||||||
|
app.use(bodyParser.urlencoded({ extended: true }));
|
||||||
|
|
||||||
// add custom middleware (note: build out to accept dynamically use what is in server/middleware/
|
// add custom middleware (note: build out to accept dynamically use what is in server/middleware/
|
||||||
app.use(requestLogger);
|
app.use(requestLogger);
|
||||||
|
|
Loading…
Add table
Reference in a new issue