[Ivan Diaz] - Add APIUtils and php api initial configuration

This commit is contained in:
Ivan Diaz 2015-10-30 23:20:35 -03:00
parent 4d709822fc
commit 001427008b
10 changed files with 69 additions and 1183 deletions

View File

@ -6,6 +6,7 @@ var express = require('express');
var gulp = require('gulp');
var gutil = require('gulp-util');
var morgan = require('morgan');
var proxy = require('express-http-proxy');
gulp.task('server', function() {
@ -15,6 +16,13 @@ gulp.task('server', function() {
server.use(morgan('dev'));
server.use(express.static(config.buildDir));
// Proxy php server api
server.use('/server', proxy('http://localhost:8080/', {
forwardPath: function(req, res) {
return require('url').parse(req.url).path;
}
}));
// Serve index.html for all routes to leave routing up to react-router
server.all('/*', function(req, res) {
res.sendFile('index.html', { root: 'build' });

View File

@ -45,6 +45,7 @@
"gulp-util": "^3.0.6",
"humps": "^0.6.0",
"jest-cli": "^0.5.10",
"jquery": "^2.1.4",
"lodash": "^3.10.0",
"messageformat": "^0.2.2",
"morgan": "^1.6.1",
@ -55,7 +56,6 @@
"react-router": "^0.13.x",
"reflux": "^0.2.9",
"run-sequence": "^1.1.1",
"superagent": "^1.2.0",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.2.x"
},

View File

@ -1,7 +1,16 @@
<?php
$app->group('/user', function () use ($app) {
$app->get('/new', function () use ($app) {
$app->get('/get/(:by)/(:value)', function () use ($app) {
echo "Returns the user with $by = $value as a json";
});
$app->post('/login', function () use ($app) {
// $app->response()->setStatus(400);
$app->response()->setBody('{ "response": true }');
});
$app->post('/add', function () use ($app) {
echo "You have the new";
});
});

45
src/lib/APIUtils.js Normal file
View File

@ -0,0 +1,45 @@
'use strict';
import $ from 'jquery';
const APIUtils = {
root: 'http://localhost:3000/server/',
getPromise(path, method, data) {
return (resolve, reject) => {
$.ajax({
url: this.root + path,
method: method,
data: data,
dataType: 'json'
})
.done(resolve)
.fail((jqXHR, textStatus) => {
reject(textStatus);
});
};
},
get(path) {
return new Promise(this.getPromise(path, 'GET'));
},
post(path, data) {
return new Promise(this.getPromise(path, 'POST', data));
},
patch(path, data) {
return new Promise(this.getPromise(path, 'PATCH', data));
},
put(path, data) {
return new Promise(this.getPromise(path, 'PUT', data));
},
del(path) {
return new Promise(this.getPromise(path, 'DELETE'));
}
};
export default APIUtils;

View File

@ -1,5 +0,0 @@
<?php
$mysql_host = 'localhost';
$mysql_user = 'os_dev';
$mysql_password = 'os_dev';
$mysql_database = 'os_dev';

View File

@ -1,12 +0,0 @@
<?php
$app->get('/hello/:name', function ($name) {
$book = RedBean::dispense('book');
$book->title = $name;
$book->author = 'Charles Xavier';
$id = RedBean::store($book);
echo $id;
});
$app->run();

View File

@ -1,9 +0,0 @@
{
"require": {
"slim/slim": "~2.0",
"gabordemooij/redbean": "~4.2"
},
"require-dev": {
"phpunit/phpunit": "5.0.*"
}
}

1143
src/server/composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +0,0 @@
<?php
require_once 'api/config.php';
require_once 'vendor/autoload.php';
use RedBeanPHP\Facade as RedBean;
RedBean::setup('mysql:host='. $mysql_host .';dbname=' . $mysql_database, $mysql_user, $mysql_password);
$app = new \Slim\Slim();
include_once 'api/index.php';

View File

@ -1,4 +1,5 @@
import Reflux from 'reflux';
import APIUtils from 'lib/APIUtils';
import UserActions from 'actions/user-actions';
@ -13,8 +14,10 @@ var UserStore = Reflux.createStore({
this.listenTo(UserActions.logout, this.logoutUser);
},
loginUser({email, password, remember}) {
console.log(`${email}:${password} (${remember})`);
loginUser(loginData) {
APIUtils.post('user/login').then(result => {
console.log(result);
});
}
});