forked from frodebjerke/something-smart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d6de352
Showing
15 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"presets": [ | ||
"es2015" | ||
], | ||
"plugins": [ | ||
"transform-object-rest-spread" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git | ||
node_modules | ||
|
||
*.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require("babel-polyfill"); | ||
require('babel-core/register'); | ||
require('./server'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "something-smart", | ||
"version": "0.0.1", | ||
"description": "Quotes and stuff", | ||
"scripts": { | ||
"local": "nodemon index.js" | ||
}, | ||
"keywords": [], | ||
"author": "frode bjerke @frodebjerke", | ||
"license": "ISC", | ||
"dependencies": { | ||
"babel": "^6.5.2", | ||
"babel-core": "^6.7.4", | ||
"babel-plugin-transform-object-rest-spread": "^6.6.5", | ||
"babel-polyfill": "^6.7.4", | ||
"babel-preset-es2015": "^6.6.0", | ||
"co": "^4.6.0", | ||
"express": "^4.13.4", | ||
"express-handlebars": "^3.0.0", | ||
"morgan": "^1.7.0", | ||
"rethinkdbdash": "^2.2.18", | ||
"winston": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^1.9.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import express from 'express'; | ||
import morgan from 'morgan'; | ||
import pages from './pages'; | ||
import exphbs from 'express-handlebars' | ||
|
||
export default function App() { | ||
const app = express(); | ||
app.use(morgan('combined')); | ||
app.engine('handlebars', exphbs({defaultLayout: 'main'})); | ||
app.set('view engine', 'handlebars'); | ||
|
||
app.use('/assets', express.static('dist')); | ||
app.use('/', pages()) | ||
|
||
return app; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import rethinkdbdash from 'rethinkdbdash'; | ||
|
||
const host = 'localhost' || process.env.SS_RDB_HOST; | ||
const dbname = 'somethingsmart' || process.env.SS_RDB_DB; | ||
|
||
const r = rethinkdbdash({ | ||
host: host, | ||
db: dbname | ||
}); | ||
|
||
export default r; | ||
export function* setupDb() { | ||
var dbList = yield r.dbList(); | ||
|
||
if (dbList.indexOf(dbname) === -1) { | ||
yield r.dbCreate(dbname); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import r, { setupDb } from './connection'; | ||
import indices from './indices'; | ||
import tables, { ensureTables} from './tables'; | ||
|
||
export default r; | ||
export { indices, tables, setupDb, ensureTables }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const r = require('./connection'); | ||
const tables = require('./tables'); | ||
|
||
export default function* () { | ||
return yield [ | ||
]; | ||
} | ||
|
||
function* ensureIndex(table, column) { | ||
try { | ||
yield r.table(table).indexCreate(column) | ||
} catch (error) { | ||
if (error.name !== 'ReqlRuntimeError') { | ||
throw new Error(error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const r = require('./connection'); | ||
|
||
const tables = { | ||
quotes: 'quotes' | ||
} | ||
|
||
export default tables; | ||
|
||
export function* ensureTables(r) { | ||
return yield Object.keys(tables).map(function* (tableName) { | ||
try { | ||
yield r.tableCreate(tableName); | ||
} catch (error) { | ||
if (error.name !== 'ReqlOpFailedError') { | ||
throw new Error(error); | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import winston from 'winston'; | ||
import App from './app'; | ||
import co from 'co'; | ||
import r, { | ||
setupDb, | ||
ensureTables, | ||
indices | ||
} from './config/rethinkdb'; | ||
|
||
co(setupDb()) | ||
.then(() => { | ||
winston.info("db setup done") | ||
return co(ensureTables(r)) | ||
.catch((err) => { | ||
winston.error('Failed to run database setup', err); | ||
throw new Error('Could not start server'); | ||
}) | ||
}) | ||
.then(() => { | ||
return co(indices()) | ||
.catch((err) => { | ||
winston.error('Failed to ensure indices'); | ||
throw new Error('Could not start server', err); | ||
}) | ||
}).catch((err) => { console.log(err)}) | ||
|
||
const app = App(); | ||
const port = process.env.PORT || 3000; | ||
app.listen(port, () => { | ||
winston.info(`Application running on port ${port}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Router } from 'express'; | ||
import co from 'co'; | ||
import { get as getQuotes } from '../repos/quote-repo'; | ||
|
||
export default function Views() { | ||
const router = Router(); | ||
|
||
router.get('*', (req, res, next) => { | ||
co(getQuotes()) | ||
.then((quotes) => { | ||
const quote = quotes[0]; | ||
res.render('index', { quote }); | ||
}) | ||
.catch((err) => { | ||
res.render('error', { err }) | ||
}) | ||
}); | ||
|
||
return router; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import r, { tables } from '../config/rethinkdb'; | ||
|
||
export function* get() { | ||
return r.table(tables.quotes); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<article> | ||
<h1>Shit went the bucket</h1> | ||
{{err}} | ||
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<article> | ||
<h1>{{quote.text}}</h1> | ||
<p>{{quote.by}}</p> | ||
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Something-smart</title> | ||
</head> | ||
<body> | ||
|
||
{{{body}}} | ||
|
||
</body> | ||
</html> |