added config var for public static folder

This commit is contained in:
bill bittner 2018-03-29 16:10:56 -07:00
parent 506c99666e
commit 3a80c4fd3b
4 changed files with 3417 additions and 3601 deletions

View file

@ -31,11 +31,12 @@ function SiteConfig () {
thumbnailChannelId : 'default',
uploadDirectory : '/home/lbry/Uploads',
};
this.routes = {};
this.update = (config) => {
if (!config) {
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...');
this.analytics = analytics;
this.assetDefaults = assetDefaults;
@ -43,6 +44,7 @@ function SiteConfig () {
this.details = details;
this.publishing = publishing;
this.customComponents = customComponents;
this.routes = routes;
};
};

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

View file

@ -8,7 +8,7 @@ const cookieSession = require('cookie-session');
const http = require('http');
const logger = require('winston');
const requestLogger = require('middleware/requestLogger.js');
const Path = require('path');
const loggerConfig = require('loggerConfig.js');
const mysqlConfig = require('mysqlConfig.js');
const siteConfig = require('siteConfig.js');
@ -43,12 +43,24 @@ function Server () {
// trust the proxy to get ip address for us
app.enable('trust proxy');
// add middleware
app.use(helmet()); // 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
// note: take in a different public folder, so it can serve it's own bundle from there?
app.use(bodyParser.json()); // 'body parser' for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // 'body parser' for parsing application/x-www-form-urlencoded
/* add middleware */
// set HTTP headers to protect against well-known web vulnerabilties
app.use(helmet());
// 'express.static' to serve static files from public directory
if (siteConfig.routes.public) {
// 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/
app.use(requestLogger);