cleaned up errors and updated build scripts

This commit is contained in:
bill bittner 2018-07-31 16:43:08 -07:00
parent dc558e9b9c
commit 60ffe5de95
28 changed files with 139 additions and 127 deletions

View file

@ -1,6 +1,5 @@
node_modules/
exports/
index.js
test/
server/render/build
client/build
node_modules/
public/bundle
server/render/build
test/

2
.gitignore vendored
View file

@ -16,4 +16,6 @@ config/siteConfig.json
public/bundle/bundle.js
public/bundle/bundle.js.map
public/bundle/Lekton-*
public/bundle/style.css

View file

@ -2,15 +2,30 @@
This repo packages the spee.ch server for use with spee.ch implementations.
### Quick start
To get started running your own version of spee.ch, visit [lbryio/www.spee.ch](https://github.com/lbryio/www.spee.ch)
### Install
Install dependencies
```
npm install spee.ch --save
npm install
```
create config file
```
npm run configure
```
build from source code
```
npm run transpile
```
create client bundle with webpack
```
npm run bundle
```
start the sever
```
npm run start
```
### Dependenceis
Make sure the following are installed
### System dependencies
Spee.ch relies on the following programs being installed on your server:
* [imagemagick](https://www.imagemagick.org/script/download.php)
* [ffmpeg](https://www.ffmpeg.org/download.html)
@ -19,6 +34,7 @@ Make sure the following are installed
* `index.js` is the entry point for the server. It creates the [express app](https://expressjs.com/), requires the routes, syncs the database, and starts the server listening on the `PORT` designated in the config file.
* the `server/routes` folder contains all of the routes for the express app
* the `server/models` folder contains all of the models which the app uses to interact with the `mysql` database. Note: this app uses the [sequelize](http://docs.sequelizejs.com/) ORM.
* the `client/` folder contains all of the client code
## Tests
* This package uses `mocha` with `chai` for testing.

View file

@ -166,7 +166,7 @@ inquirer
})
.then(() => {
console.log('\nYou\'re all done!');
console.log('Next step: run "npm run start:dev" to start your server!');
console.log('Next step: run "npm run build" to build your server, then "npm run start" to start your server!');
console.log('If you want to change any settings, you can edit the files in the "/config" folder.');
process.exit(0);
})

View file

@ -4,4 +4,4 @@ import { onHandleShowPageUri } from './show';
export default {
onHandleShowPageUri,
}
};

View file

@ -4,7 +4,7 @@ import {
updateChannelAvailability,
updateChannelCreateName,
updateChannelCreatePassword,
createChannel
createChannel,
} from '../../actions/channelCreate';
const mapStateToProps = ({channelCreate: { name, password, error, status }}) => {
@ -13,7 +13,7 @@ const mapStateToProps = ({channelCreate: {name, password, error, status }}) => {
password,
error,
status,
}
};
};
const mapDispatchToProps = {

View file

@ -4,4 +4,4 @@ import { handleShowPageUri } from './show_uri';
export default {
rootSaga,
handleShowPageUri,
}
};

View file

@ -4,24 +4,26 @@
"description": "an npm package that exports a customizeable spee.ch server",
"main": "index.js",
"scripts": {
"bundle": "webpack --config webpack.config.js",
"bundle:dev": "webpack --config webpack.config.js --watch",
"configure": "node cli/configure.js",
"fix": "eslint . --fix",
"lint": "eslint .",
"precommit": "eslint .",
"start": "npm run server",
"start:dev": "builder concurrent transpile:dev bundle:dev bundle:dev",
"server": "node server.js",
"server:dev": "nodemon server.js",
"test": "mocha --recursive",
"test:no-lbc": "npm test -- --grep @usesLbc --invert",
"lint": "eslint .",
"fix": "eslint . --fix",
"precommit": "eslint .",
"build": "builder concurrent transpile:server transpile:client transpile:client_custom webpack",
"build:dev": "builder concurrent transpile:server:dev transpile:client:dev transpile:client_custom:dev webpack:dev",
"start": "node server.js",
"start:dev": "builder concurrent build:dev server:dev",
"server:dev": "nodemon server.js",
"transpile": "builder concurrent transpile:server transpile:client transpile:client_custom",
"transpile:dev": "builder concurrent transpile:server:dev transpile:client:dev transpile:client_custom:dev",
"transpile:server": "babel server/render/src -d server/render/build",
"transpile:server:dev": "babel server/render/src -w -d server/render/build",
"transpile:client": "babel client/src -d client/build",
"transpile:client:dev": "babel client/src -w -d client/build",
"transpile:client_custom": "babel client_custom/src -d client_custom/build",
"transpile:client_custom:dev": "babel client_custom/src -w -d client_custom/build",
"webpack": "webpack --config webpack.config.js",
"webpack:dev": "webpack --config webpack.config.js --watch"
"transpile:client_custom:dev": "babel client_custom/src -w -d client_custom/build"
},
"repository": {
"type": "git",

View file

@ -21,9 +21,9 @@ try {
}
try {
const SpeechServer = require('./server');
const server = new SpeechServer();
server.start();
const Server = require('./server/index.js');
const speech = new Server();
speech.start();
} catch (error) {
console.log('server startup error:', error);
process.exit(1);

View file

@ -25,9 +25,9 @@ const channelAvailability = ({ ip, originalUrl, params: { name } }, res) => {
data : isAvailable,
};
if (isAvailable) {
responseObject['message'] = `${name} is available`
responseObject['message'] = `${name} is available`;
} else {
responseObject['message'] = `${name} is already in use`
responseObject['message'] = `${name} is already in use`;
}
res.status(200).json(responseObject);
sendGATimingEvent('end-to-end', 'channel name availability', name, gaStartTime, Date.now());

View file

@ -1,6 +1,5 @@
const { handleErrorResponse } = require('../../../utils/errorHandlers.js');
const getChannelClaims = require('./getChannelClaims.js');
const logger = require('winston');
const NO_CHANNEL = 'NO_CHANNEL';

View file

@ -18,7 +18,7 @@ const channelData = ({ ip, originalUrl, body, params }, res) => {
.then(data => {
res.status(200).json({
success: true,
data
data,
});
})
.catch(error => {

View file

@ -17,9 +17,9 @@ const claimAvailability = ({ ip, originalUrl, params: { name } }, res) => {
data : isAvailable,
};
if (isAvailable) {
responseObject['message'] = `That claim name is available`
responseObject['message'] = `That claim name is available`;
} else {
responseObject['message'] = `That url is already in use`
responseObject['message'] = `That url is already in use`;
}
res.status(200).json(responseObject);
sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now());

View file

@ -16,12 +16,12 @@ const claimData = ({ ip, originalUrl, body, params }, res) => {
if (!claimInfo) {
return res.status(404).json({
success: false,
message: 'No claim could be found'
message: 'No claim could be found',
});
}
res.status(200).json({
success: true,
data: claimInfo
data : claimInfo,
});
})
.catch(error => {

View file

@ -29,7 +29,7 @@ const claimGet = ({ ip, originalUrl, params }, res) => {
.then(() => {
const fileData = createFileRecordDataAfterGet(resolveResult, getResult);
const upsertCriteria = { name, claimId };
return db.upsert(db.File, fileData, upsertCriteria, 'File')
return db.upsert(db.File, fileData, upsertCriteria, 'File');
})
.then(() => {
const { message, completed } = getResult;

View file

@ -35,7 +35,7 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
if (disabled) {
return res.status(503).json({
success: false,
message: disabledMessage
message: disabledMessage,
});
}
// define variables
@ -58,14 +58,15 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
checkClaimAvailability(name),
createPublishParams(filePath, name, title, description, license, nsfw, thumbnail, channelName, channelClaimId),
createThumbnailPublishParams(thumbnailFilePath, name, license, nsfw),
])
]);
})
.then(([ claimAvailable, publishParams, thumbnailPublishParams ]) => {
if (!claimAvailable) {
throw {
const error = {
name : CLAIM_TAKEN,
message: 'That claim name is already taken'
message: 'That claim name is already taken',
};
throw error;
}
// publish the thumbnail, if one exists
if (thumbnailPublishParams) {
@ -91,7 +92,7 @@ const claimPublish = ({ body, files, headers, ip, originalUrl, user, tor }, res)
sendGATimingEvent('end-to-end', 'publish', fileType, gaStartTime, Date.now());
})
.catch(error => {
if (error.name = CLAIM_TAKEN) {
if (error.name === CLAIM_TAKEN) {
res.status(400).json({
success: false,
message: error.message,

View file

@ -5,7 +5,7 @@ const { publishing: {
thumbnailChannelId,
additionalClaimAddresses,
disabled,
disabledMessage
disabledMessage,
} } = require('@config/siteConfig');
/*
@ -22,7 +22,7 @@ const publishingConfig = (req, res) => {
thumbnailChannelId,
additionalClaimAddresses,
disabled,
disabledMessage
disabledMessage,
});
};

View file

@ -6,7 +6,6 @@ const getOEmbedDataForAsset = require('./getOEmbedDataForAsset');
const parseSpeechUrl = require('./parseSpeechUrl');
const getOEmbedData = (req, res) => {
const { query: { url, format } } = req;
logger.debug('req url', url);
logger.debug('req format', format);
@ -32,7 +31,7 @@ const getOEmbedData = (req, res) => {
return res.status(503).json({
success: false,
message: 'xml format is not implemented yet',
})
});
} else {
return res.status(200).json(data);
}
@ -42,8 +41,7 @@ const getOEmbedData = (req, res) => {
success: false,
message: error,
});
})
});
} else {
getOEmbedDataForAsset(channelName, channelClaimId, claimName, claimId)
.then(data => {
@ -51,7 +49,7 @@ const getOEmbedData = (req, res) => {
return res.status(503).json({
success: false,
message: 'xml format is not implemented yet',
})
});
} else {
return res.status(200).json(data);
}
@ -61,7 +59,7 @@ const getOEmbedData = (req, res) => {
success: false,
message: error,
});
})
});
}
};

View file

@ -18,7 +18,7 @@ const getTorList = (req, res) => {
res.status(500).json({
success: false,
error,
})
});
});
};

View file

@ -40,11 +40,9 @@ const serveByClaim = (req, res) => {
getClaimIdAndServeAsset(null, null, claimName, null, originalUrl, ip, res);
sendGAServeEvent(headers, ip, originalUrl);
} catch (error) {
return res.status(400).json({success: false, message: error.message});
}
};
module.exports = serveByClaim;

View file

@ -41,11 +41,9 @@ const serverByIdentifierAndClaim = (req, res) => {
getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res);
sendGAServeEvent(headers, ip, originalUrl);
} catch (error) {
return res.status(400).json({success: false, message: error.message});
}
};
module.exports = serverByIdentifierAndClaim;

View file

@ -2,7 +2,7 @@ const logout = (req, res) => {
req.logout();
const responseObject = {
success: true,
message: 'you successfully logged out'
message: 'you successfully logged out',
};
res.status(200).json(responseObject);
};

View file

@ -86,7 +86,7 @@ function Server () {
dataType : 'text',
defaultLayout: 'embed',
partialsDir : Path.join(viewsPath, '/partials'),
layoutsDir: Path.join(viewsPath, '/layouts')
layoutsDir : Path.join(viewsPath, '/layouts'),
}));
app.set('views', viewsPath);
app.set('view engine', 'handlebars');
@ -110,7 +110,7 @@ function Server () {
this.server.listen(PORT, () => {
logger.info(`Server is listening on PORT ${PORT}`);
resolve();
})
});
});
};
this.syncDatabase = () => {
@ -118,7 +118,7 @@ function Server () {
return createDatabaseIfNotExists()
.then(() => {
db.sequelize.sync();
})
});
};
this.performChecks = () => {
if (!performChecks) {
@ -130,7 +130,7 @@ function Server () {
])
.then(([walletBalance]) => {
logger.info('Starting LBC balance:', walletBalance);
})
});
};
this.performUpdates = () => {
if (!performUpdates) {
@ -144,7 +144,7 @@ function Server () {
.then(([updatedBlockedList, updatedTorList]) => {
logger.info('Blocked list updated, length:', updatedBlockedList.length);
logger.info('Tor list updated, length:', updatedTorList.length);
})
});
};
this.start = () => {
this.initialize();
@ -158,14 +158,14 @@ function Server () {
return Promise.all([
this.performChecks(),
this.performUpdates(),
])
]);
})
.then(() => {
logger.info('Spee.ch startup is complete');
})
.catch(error => {
if (error.code === 'ECONNREFUSED') {
return logger.error('Connection refused. The daemon may not be running.')
return logger.error('Connection refused. The daemon may not be running.');
} else if (error.code === 'EADDRINUSE') {
return logger.error('Server could not start listening. The port is already in use.');
} else if (error.message) {

View file

@ -19,7 +19,7 @@ const sequelize = new Sequelize(database, username, password, {
host : 'localhost',
dialect : 'mysql',
dialectOptions: {
decimalNumbers: true
decimalNumbers: true,
},
logging: false,
pool : {

View file

@ -21,7 +21,6 @@ const getTorList = require('../../controllers/api/tor');
const getBlockedList = require('../../controllers/api/blocked');
const getOEmbedData = require('../../controllers/api/oEmbed');
module.exports = (app) => {
// channel routes
app.get('/api/channel/availability/:name', torCheckMiddleware, channelAvailability);
@ -48,5 +47,5 @@ module.exports = (app) => {
// blocked
app.get('/api/blocked', torCheckMiddleware, getBlockedList);
// open embed
app.get('/api/oembed', torCheckMiddleware, getOEmbedData)
app.get('/api/oembed', torCheckMiddleware, getOEmbedData);
};