Skip to content

Commit

Permalink
first code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Loscalzo committed Sep 24, 2020
0 parents commit 00c3df2
Show file tree
Hide file tree
Showing 20 changed files with 3,492 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
slack_key=xoxb
slack__client_id=
slack__client_secret=
slack__access_token=xoxp
imgur__client_id=
imgur__client_secret=
REDIS_URL=redis://127.0.0.1:6379
GITHUB__ACCESS_KEY=
GITHUB__REPO=
GITHUB__OWNER=
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
.env.*
node_modules
!.env.example
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/bin/www"
},
{
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
}
]
}
42 changes: 42 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

let dotenv = require('dotenv-flow');
dotenv.config();

const { createEventAdapter } = require('@slack/events-api');
const slackEvents = createEventAdapter(process.env.slack_key);

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

// Create an express application
const app = express();
(async () => {

app.use(logger('dev'));
// Plug the adapter in as a middleware
app.use('/my/path', slackEvents.requestListener());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/auth', usersRouter);

function errorHandler(err, req, res, next) {
if (res.headersSent) {
return next(err);
}
res.status(500);
res.status(500).send('Something broke!');
return res;
}

app.use(errorHandler);
})();

module.exports = app;
90 changes: 90 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('arturito:server');
var http = require('http');

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

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

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

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

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

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

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

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var 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.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
12 changes: 12 additions & 0 deletions configs/redis.work.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = async () => {
let REDIS_URL = process.env.REDIS_URL || "redis://127.0.0.1:6379";
let Queue = require('bull');

let workQueue = new Queue('work', REDIS_URL);

// workQueue.on('global:completed', (jobId, result) => {
// console.log(`Job completed with result ${result}`);
// });

return workQueue;
}
22 changes: 22 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

services:
redis:
image: "redis:alpine"
ports:
- "6379:6379"
networks:
- robotito
backend:
build:
context: .
dockerfile: node.dockerfile
ports:
- "3000:3000"
environment:
- NODE_ENV=production
networks:
- robotito
depends_on:
- redis
networks:
robotito:
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

services:
redis:
image: "redis:alpine"
ports:
- "6379:6379"
22 changes: 22 additions & 0 deletions node.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM node:14.10.1-alpine

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

EXPOSE 3000

ENV NODE_ENV=production

CMD npm run prod
Loading

0 comments on commit 00c3df2

Please sign in to comment.