Skip to content

Instantly share code, notes, and snippets.

View abachuk's full-sized avatar
✍️
dev manager by day, writing code at night

Alex Bachuk abachuk

✍️
dev manager by day, writing code at night
View GitHub Profile
import express from 'express';
import axios from 'axios';
import multer from 'multer';
const app = express();
/**
... express.js boilerplate
routes, middlewares, helpers, loggers, etc
**/
actions: {
sendContactForm() {
// Getting input values.
// TODO: add validation before trying to save the values.
const submittedForm = {
name: this.get('name'),
email: this.get('email'),
company: this.get('company'),
phone: this.get('phone'),
message: this.get('message'),
import Ember from 'ember';
// because it's loading through browserify, we're preficing it with npm:
import AWS from 'npm:aws-sdk'
// It's recommended to keep all your API keys in the environment.js file
// and pass them through environment variables
import config from '../config/environment';
const ses = new AWS.SES({
apiVersion: '2010-12-01',
accessKeyId: config.aws.accessKeyId,
import axios from 'axios';
import cloudinary from 'cloudinary';
export default function fileUploadMiddleware(req, res) {
cloudinary.uploader.upload_stream((result) => {
axios({
url: '/api/upload', //API endpoint that needs file URL from CDN
method: 'post',
data: {
url: result.secure_url,
@abachuk
abachuk / server.js
Created June 26, 2017 21:47
node.js using fileUploadMiddleware for streaming files to CDN
import multer from 'multer';
import cloudinary from 'cloudinary';
import fileUploadMiddleware from './fileUploadMiddleware';
/* your servrer init and express code here */
cloudinary.config({
cloud_name: 'xxx',
api_key: 'xxxx',
api_secret: 'xxxxx',
@abachuk
abachuk / react-file-upload-to-cdn-handler.js
Created June 26, 2017 22:03
upload files to custom node middleware and CDN, get response back in react.js
import React, { Component } from 'react';
import axios from 'axios';
class uploadMyFile extends Component {
handleUploadFile = (event) => {
const data = new FormData();
data.append('file', event.target.files[0]);
data.append('name', 'some value user types');
data.append('description', 'some value user types');
// '/files' is your node.js route that triggers our middleware
import axios from 'axios';
export const GET_POSTS_START = 'GET_POSTS_START';
export const GET_POSTS_SUCCESS = 'GET_POSTS_SUCCESS';
export const GET_POSTS_FAIL = 'GET_POSTS_FAIL';
const getPostsStart = () => ({
type: GET_POSTS_START,
});
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import moxios from 'moxios';
import expect from 'expect';
import * as actions from './getPosts';
import getPostsMock from '../../mocks/getPostsMock';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
import reducer from './getPostsReducer';
import * as types from '../actions/posts/getPostsReduxAction';
import expect from 'expect';
describe('team reducer', () => {
it('should return the initial state');
it('should handle GET_POST_SUCCESS');
it('should handle UPDATE_POST_SUCCESS');
it('should handle GET_POST_FAIL');
it('should handle GET_POST_START');
import reducer from './getPostReducer';
import * as actions from '../actions/posts/getPost';
import { UPDATE_POST_SUCCESS } from '../actions/posts/updatePost';
import expect from 'expect';
import getPostMock from '../mocks/getPostMock';
describe('post reducer', () => {
it('should return the initial state', () => {
expect(reducer(undefined, {})).toEqual({});
});