Skip to content

Commit

Permalink
Merge pull request #1 from plaidev/convert_to_js
Browse files Browse the repository at this point in the history
decaffeinate
  • Loading branch information
jumpei_ikegami authored Aug 31, 2017
2 parents 4687ad3 + 759f852 commit e1a5e07
Show file tree
Hide file tree
Showing 23 changed files with 557 additions and 505 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
/npm-debug.log
/Procfile
/.buildpacks
/.buildpacks
/config.js
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
- KARTEのmessageとassignのWebhookやAPIを使ったbotのサンプルです.

## 使い方
- [ ] `npm start`で5000番でサーバーを立ち上げる.
- [ ] `_config.coffee`ファイルを作成し、必要な設定値を追加する.
- [ ] KARTE管理画面から、botの設定を行います.
- [ ] `config.js`ファイルに必要な設定値を追加します.
- 以下のような内容で作成してください.

```coffee
```js
module.exports = {
KARTE_URL: "https://t.karte.io"
KARTE_BOT_APPLICATION_KEY: "bot設定画面のApplicationKeyを設定"
KARTE_BOT_SECRET_KEY: "bot設定画面のSecretKeyを設定"
ALGOLIA_APPLICATION_ID: "AlgoliaのApplicationIdを設定(Algolia検索を使う場合)"
ALGOLIA_API_KEY: "AlgoliaのApiKeyを設定(Algolia検索を使う場合)"
ALGOLIA_INDEX_NAME: "AlgoliaのIndexNameを設定(Algolia検索を使う場合)"
KARTE_URL: "https://t.karte.io",
KARTE_BOT_APPLICATION_KEY: "bot設定画面のApplicationKeyを設定",
KARTE_BOT_SECRET_KEY: "bot設定画面のSecretKeyを設定",
ALGOLIA_APPLICATION_ID: "AlgoliaのApplicationIdを設定(Algolia検索を使う場合)",
ALGOLIA_API_KEY: "AlgoliaのApiKeyを設定(Algolia検索を使う場合)",
ALGOLIA_INDEX_NAME: "AlgoliaのIndexNameを設定(Algolia検索を使う場合)",
A3RT_API_KEY: "A3RTのApiKeyを設定(A3RT APIを使う場合)"
}
```

- [ ] `npm start`で、port:5000番でサーバーが立ち上がります.

## bot仕様
- `/echo`
- 来たメッセージをそのまま返します.
Expand Down
49 changes: 0 additions & 49 deletions app.coffee

This file was deleted.

54 changes: 54 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const routes = require('./routes/index');
const bot = require('./routes/bot');
const app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/bot', bot);
// catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('Not Found');
err.status = 404;
next(err);
});
app.use((err, req, res, next) => {
console.log('err', err);
return next();
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
}
);
});
}
// production error handler
// no stacktraces leaked to user
app.use((err, req, res, next) => {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
78 changes: 0 additions & 78 deletions bin/www.coffee

This file was deleted.

85 changes: 85 additions & 0 deletions bin/www.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Module dependencies.
*/

const app = require('../app');
const debug = require('debug')('myapp:server');
const http = require('http');

/**
* Normalize a port into a number, string, or false.
*/

const normalizePort = (val) => {
let port;
port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
};

/**
* Get port from environment and store in Express.
*/

const port = normalizePort(process.env.PORT || '5000');


/**
* Event listener for HTTP server "error" event.
*/

const onError = (error) => {
if (error.syscall !== 'listen') {
throw error;
}
const bind = typeof port === 'string' ? `Pipe ${port}` : `Port ${port}`;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
};

/**
* Event listener for HTTP server "listening" event.
*/

const onListening = () => {
const addr = server.address();
const bind = typeof addr === 'string' ? `pipe ${addr}` : `port ${addr.port}`;
debug(`Listening on ${bind}`);
};

app.set('port', port);

/**
* Create HTTP server.
*/

const server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

// ---
// generated by js2coffee 2.2.0
9 changes: 0 additions & 9 deletions config.coffee

This file was deleted.

9 changes: 9 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
KARTE_URL: "https://t.karte.io",
KARTE_BOT_APPLICATION_KEY: "",
KARTE_BOT_SECRET_KEY: "",
ALGOLIA_APPLICATION_ID: "",
ALGOLIA_API_KEY: "",
ALGOLIA_INDEX_NAME: "",
A3RT_API_KEY: ""
};
30 changes: 0 additions & 30 deletions logics/_a3rt.coffee

This file was deleted.

Loading

0 comments on commit e1a5e07

Please sign in to comment.