mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-31 01:35:15 +02:00
[Ivan Diaz] - Add APIUtils and php api initial configuration
This commit is contained in:
parent
4d709822fc
commit
001427008b
@ -6,6 +6,7 @@ var express = require('express');
|
|||||||
var gulp = require('gulp');
|
var gulp = require('gulp');
|
||||||
var gutil = require('gulp-util');
|
var gutil = require('gulp-util');
|
||||||
var morgan = require('morgan');
|
var morgan = require('morgan');
|
||||||
|
var proxy = require('express-http-proxy');
|
||||||
|
|
||||||
gulp.task('server', function() {
|
gulp.task('server', function() {
|
||||||
|
|
||||||
@ -15,6 +16,13 @@ gulp.task('server', function() {
|
|||||||
server.use(morgan('dev'));
|
server.use(morgan('dev'));
|
||||||
server.use(express.static(config.buildDir));
|
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
|
// Serve index.html for all routes to leave routing up to react-router
|
||||||
server.all('/*', function(req, res) {
|
server.all('/*', function(req, res) {
|
||||||
res.sendFile('index.html', { root: 'build' });
|
res.sendFile('index.html', { root: 'build' });
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
"gulp-util": "^3.0.6",
|
"gulp-util": "^3.0.6",
|
||||||
"humps": "^0.6.0",
|
"humps": "^0.6.0",
|
||||||
"jest-cli": "^0.5.10",
|
"jest-cli": "^0.5.10",
|
||||||
|
"jquery": "^2.1.4",
|
||||||
"lodash": "^3.10.0",
|
"lodash": "^3.10.0",
|
||||||
"messageformat": "^0.2.2",
|
"messageformat": "^0.2.2",
|
||||||
"morgan": "^1.6.1",
|
"morgan": "^1.6.1",
|
||||||
@ -55,7 +56,6 @@
|
|||||||
"react-router": "^0.13.x",
|
"react-router": "^0.13.x",
|
||||||
"reflux": "^0.2.9",
|
"reflux": "^0.2.9",
|
||||||
"run-sequence": "^1.1.1",
|
"run-sequence": "^1.1.1",
|
||||||
"superagent": "^1.2.0",
|
|
||||||
"vinyl-source-stream": "^1.1.0",
|
"vinyl-source-stream": "^1.1.0",
|
||||||
"watchify": "^3.2.x"
|
"watchify": "^3.2.x"
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
$app->group('/user', function () use ($app) {
|
$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";
|
echo "You have the new";
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
45
src/lib/APIUtils.js
Normal file
45
src/lib/APIUtils.js
Normal 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;
|
@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
$mysql_host = 'localhost';
|
|
||||||
$mysql_user = 'os_dev';
|
|
||||||
$mysql_password = 'os_dev';
|
|
||||||
$mysql_database = 'os_dev';
|
|
@ -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();
|
|
@ -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
1143
src/server/composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -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';
|
|
@ -1,4 +1,5 @@
|
|||||||
import Reflux from 'reflux';
|
import Reflux from 'reflux';
|
||||||
|
import APIUtils from 'lib/APIUtils';
|
||||||
|
|
||||||
import UserActions from 'actions/user-actions';
|
import UserActions from 'actions/user-actions';
|
||||||
|
|
||||||
@ -13,8 +14,10 @@ var UserStore = Reflux.createStore({
|
|||||||
this.listenTo(UserActions.logout, this.logoutUser);
|
this.listenTo(UserActions.logout, this.logoutUser);
|
||||||
},
|
},
|
||||||
|
|
||||||
loginUser({email, password, remember}) {
|
loginUser(loginData) {
|
||||||
console.log(`${email}:${password} (${remember})`);
|
APIUtils.post('user/login').then(result => {
|
||||||
|
console.log(result);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user