Folder structure #398
7 changed files with 110 additions and 173 deletions
|
@ -1,23 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
development: {
|
|
||||||
username: '',
|
|
||||||
password: '',
|
|
||||||
database: '',
|
|
||||||
host : '127.0.0.1',
|
|
||||||
dialect : 'mysql',
|
|
||||||
},
|
|
||||||
test: {
|
|
||||||
username: '',
|
|
||||||
password: '',
|
|
||||||
database: '',
|
|
||||||
host : '127.0.0.1',
|
|
||||||
dialect : 'mysql',
|
|
||||||
},
|
|
||||||
production: {
|
|
||||||
username: '',
|
|
||||||
password: '',
|
|
||||||
database: '',
|
|
||||||
host : '127.0.0.1',
|
|
||||||
dialect : 'mysql',
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -1,44 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
wallet: {
|
|
||||||
lbryClaimAddress: null, // choose an address from your lbry wallet
|
|
||||||
},
|
|
||||||
analytics: {
|
|
||||||
googleId: null, // google id for analytics tracking; leave `null` if not applicable
|
|
||||||
},
|
|
||||||
logging: {
|
|
||||||
logLevel : null, // options: silly, debug, verbose, info
|
|
||||||
slackWebHook : null, // enter a webhook if you wish to push logs to slack; otherwise leave as `null`
|
|
||||||
slackErrorChannel: null, // enter a slack channel (#example) for errors to be sent to; otherwise leave null
|
|
||||||
slackInfoChannel : null, // enter a slack channel (#info) for info level logs to be sent to otherwise leave null
|
|
||||||
},
|
|
||||||
session: {
|
|
||||||
sessionKey: null, // enter a secret key to be used for session encryption
|
|
||||||
},
|
|
||||||
files: {
|
|
||||||
uploadDirectory: null, // enter file path to where uploads/publishes should be stored
|
|
||||||
},
|
|
||||||
site: {
|
|
||||||
title: 'Spee.ch',
|
|
||||||
name : 'Spee.ch',
|
|
||||||
host : 'https://spee.ch',
|
|
||||||
description: 'Open-source, decentralized image and video sharing.'
|
|
||||||
},
|
|
||||||
publish: {
|
|
||||||
thumbnailChannel : '@channelName', // create a channel to use for thumbnail images
|
|
||||||
thumbnailChannelId: 'xyz123...', // the channel_id (claim id) for the channel above
|
|
||||||
}
|
|
||||||
claim: {
|
|
||||||
defaultTitle : 'Spee.ch',
|
|
||||||
defaultThumbnail : 'https://spee.ch/assets/img/video_thumb_default.png',
|
|
||||||
defaultDescription: 'Open-source, decentralized image and video sharing.',
|
|
||||||
},
|
|
||||||
testing: {
|
|
||||||
testChannel : '@testpublishchannel', // a channel to make test publishes in
|
|
||||||
testChannelId : 'xyz123...', // the claim id for the test channel
|
|
||||||
testChannelPassword: 'password', // password for the test channel
|
|
||||||
},
|
|
||||||
api: {
|
|
||||||
apiHost: 'localhost',
|
|
||||||
apiPort: '5279',
|
|
||||||
},
|
|
||||||
};
|
|
104
index.js
104
index.js
File diff suppressed because one or more lines are too long
1
index.js.map
Normal file
1
index.js.map
Normal file
File diff suppressed because one or more lines are too long
|
@ -13,7 +13,7 @@
|
||||||
"precommit": "eslint .",
|
"precommit": "eslint .",
|
||||||
"babel": "babel",
|
"babel": "babel",
|
||||||
"build-dev": "webpack --config webpack.dev.js",
|
"build-dev": "webpack --config webpack.dev.js",
|
||||||
"build-prod": "webpack --config webpack.prod.js"
|
"build": "webpack --config webpack.prod.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
102
server.js
Normal file
102
server.js
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
// load dependencies
|
||||||
|
const express = require('express');
|
||||||
|
const bodyParser = require('body-parser');
|
||||||
|
const expressHandlebars = require('express-handlebars');
|
||||||
|
const Handlebars = require('handlebars');
|
||||||
|
const { populateLocalsDotUser, serializeSpeechUser, deserializeSpeechUser } = require('./helpers/authHelpers.js');
|
||||||
|
const config = require('./config/speechConfig.js');
|
||||||
|
const logger = require('winston');
|
||||||
|
const helmet = require('helmet');
|
||||||
|
const PORT = 3000; // set port
|
||||||
|
const app = express(); // create an Express application
|
||||||
|
const passport = require('passport');
|
||||||
|
const cookieSession = require('cookie-session');
|
||||||
|
|
||||||
|
// configure logging
|
||||||
|
const logLevel = config.logging.logLevel;
|
||||||
|
require('./config/loggerConfig.js')(logger, logLevel);
|
||||||
|
require('./config/slackConfig.js')(logger);
|
||||||
|
|
||||||
|
// check for global config variables
|
||||||
|
require('./helpers/configVarCheck.js')();
|
||||||
|
|
||||||
|
// 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
|
||||||
|
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
|
||||||
|
app.use((req, res, next) => { // custom logging middleware to log all incoming http requests
|
||||||
|
logger.verbose(`Request on ${req.originalUrl} from ${req.ip}`);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
// configure passport
|
||||||
|
passport.serializeUser(serializeSpeechUser);
|
||||||
|
passport.deserializeUser(deserializeSpeechUser);
|
||||||
|
const localSignupStrategy = require('./passport/local-signup.js');
|
||||||
|
const localLoginStrategy = require('./passport/local-login.js');
|
||||||
|
passport.use('local-signup', localSignupStrategy);
|
||||||
|
passport.use('local-login', localLoginStrategy);
|
||||||
|
// initialize passport
|
||||||
|
app.use(cookieSession({
|
||||||
|
name : 'session',
|
||||||
|
keys : [config.session.sessionKey],
|
||||||
|
maxAge: 24 * 60 * 60 * 1000, // 24 hours
|
||||||
|
}));
|
||||||
|
app.use(passport.initialize());
|
||||||
|
app.use(passport.session());
|
||||||
|
|
||||||
|
// configure handlebars & register it with express app
|
||||||
|
const hbs = expressHandlebars.create({
|
||||||
|
defaultLayout: 'embed', // sets the default layout
|
||||||
|
handlebars : Handlebars, // includes basic handlebars for access to that library
|
||||||
|
});
|
||||||
|
app.engine('handlebars', hbs.engine);
|
||||||
|
app.set('view engine', 'handlebars');
|
||||||
|
|
||||||
|
// middleware to pass user info back to client (for handlebars access), if user is logged in
|
||||||
|
app.use(populateLocalsDotUser);
|
||||||
|
|
||||||
|
// start the server
|
||||||
|
const startServer = (mysqlConfig) => {
|
||||||
|
const db = require('./models')(mysqlConfig); // require our models for syncing
|
||||||
|
db.sequelize
|
||||||
|
// sync sequelize
|
||||||
|
.sync()
|
||||||
|
// require routes
|
||||||
|
.then(() => {
|
||||||
|
require('./routes/auth-routes.js')(app);
|
||||||
|
require('./routes/api-routes.js')(app);
|
||||||
|
require('./routes/page-routes.js')(app);
|
||||||
|
require('./routes/serve-routes.js')(app);
|
||||||
|
require('./routes/fallback-routes.js')(app);
|
||||||
|
const http = require('http');
|
||||||
|
return http.Server(app);
|
||||||
|
})
|
||||||
|
// start the server
|
||||||
|
.then(server => {
|
||||||
|
server.listen(PORT, () => {
|
||||||
|
logger.info('Trusting proxy?', app.get('trust proxy'));
|
||||||
|
logger.info(`Server is listening on PORT ${PORT}`);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
logger.error(`Startup Error:`, error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
hello () {
|
||||||
|
console.log('hello world');
|
||||||
|
},
|
||||||
|
speak (something) {
|
||||||
|
console.log(something);
|
||||||
|
},
|
||||||
|
start (config) {
|
||||||
|
const { mysqlConfig } = config;
|
||||||
|
startServer(mysqlConfig);
|
||||||
|
},
|
||||||
|
};
|
|
@ -10,9 +10,10 @@ module.exports = {
|
||||||
externals: [nodeExternals()],
|
externals: [nodeExternals()],
|
||||||
entry : ['babel-polyfill', 'whatwg-fetch', './server.js'],
|
entry : ['babel-polyfill', 'whatwg-fetch', './server.js'],
|
||||||
output : {
|
output : {
|
||||||
path : Path.join(__dirname, '/'),
|
path : Path.join(__dirname, '/'),
|
||||||
publicPath: '/',
|
publicPath : '/',
|
||||||
filename : 'index.js',
|
filename : 'index.js',
|
||||||
|
libraryExport: 'default',
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
|
|
Loading…
Add table
Reference in a new issue