This file contains hidden or 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
unless Rails.env.production? | |
bot_files = Dir[Rails.root.join('app', 'messenger_bot', '**', '*.rb')] | |
bot_reloader = ActiveSupport::FileUpdateChecker.new(bot_files) do | |
bot_files.each{ |file| require_dependency file } | |
end | |
ActionDispatch::Callbacks.to_prepare do | |
bot_reloader.execute_if_updated | |
end |
This file contains hidden or 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
// tracker middleware | |
app.use((req, res, next) => { | |
if (req.metadata.event) { | |
tracking(req.metadata.event); | |
next(); | |
} | |
}); | |
// logger middleware | |
app.use('/data', (req, res, next) => { |
This file contains hidden or 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
app.get('/data/:entry_id', (req, res, next) => { | |
next(); | |
}); | |
app.get('/data/:entry_id/filtered', (req, res, next) => { | |
dataFilterService(req.result) | |
.then((apiResult) => { | |
req.metadata = { | |
info: 'data is filtered', | |
event: 'api.result.received' |
This file contains hidden or 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
app.param('entry_id', (req, res, next, entry_id) => { | |
getDataById(entry_id) | |
.then((data) => { | |
req.metadata = { | |
info: 'data is received', | |
event: 'data.received' | |
}; | |
req.result = data; |
This file contains hidden or 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
app.get('/data/:entry_id', (req, res, next) => { | |
const { entry_id } = req.params; | |
database.getById(id) | |
.then((data) => { | |
logger('[INFO] data is received'); | |
tracking('data.received', {id: id}); | |
return res.json(data); | |
}) | |
.catch(next); |
This file contains hidden or 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
app.get('/data/:entry_id', (req, res, next) => { | |
const { entry_id } = req.params; | |
database.getById(id) | |
.then((data) => { | |
return res.json(data); | |
}) | |
.catch((error) => { | |
logger('[ERROR] ', error.message); | |
exceptionCatcher(error); |
This file contains hidden or 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
app.get('/data/:id/filtered', (req, res, next) => { | |
const { id } = req.params; | |
database.getById(id) | |
.then((data) => { | |
logger('[INFO] data is received'); | |
tracking('data.received', {id: id}); | |
return data; | |
}) | |
.then((data) => dataFilterService({id: data})) |
This file contains hidden or 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
const middleware = require('../middlewares/my-middweware'); | |
const next = sinon.spy(); | |
const req = {}; | |
const res = {}; | |
describe('test my middleware', () => { | |
it('tests input and output', () => { | |
middleware(req, res, next); | |
expect(next).to.have.been.called; |
This file contains hidden or 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
const express = require('express'); | |
const Promise = require('bluebird'); | |
const app = express(); | |
const logger = console.log; | |
const tracking = console.log; | |
const exceptionCatcher = console.error; | |
const getDataById = () => new Promise((resolve, reject) => { | |
resolve({data: 'I am response'}); |
This file contains hidden or 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
'use strict'; | |
var React = require('react-native'); | |
var { | |
AppRegistry, | |
StyleSheet, | |
Text, | |
View, | |
NativeModules, | |
TouchableHighlight, |