a better solution than renaming all the paths
This commit is contained in:
parent
562da81a0f
commit
da026a3003
28 changed files with 54 additions and 54 deletions
|
@ -1,13 +1,12 @@
|
|||
import request from 'request'
|
||||
const request = require('request')
|
||||
|
||||
function apiProxyMiddleware (req, res, next) {
|
||||
if (true) { // is application/json
|
||||
if (!req.xhr) {
|
||||
return next()
|
||||
}
|
||||
console.log(req.get('Content-Type'))
|
||||
const method = req.method.toLowerCase()
|
||||
req.pipe(
|
||||
request[method](url, {
|
||||
request[method](process.env.API + req.originalUrl, {
|
||||
headers: {
|
||||
...req.headers,
|
||||
host: process.env.API
|
||||
|
@ -18,4 +17,4 @@ function apiProxyMiddleware (req, res, next) {
|
|||
.pipe(res)
|
||||
}
|
||||
|
||||
export default apiProxyMiddleware
|
||||
module.exports = apiProxyMiddleware
|
|
@ -71,6 +71,7 @@
|
|||
<script type="text/javascript">
|
||||
var Metamaps = {
|
||||
ServerData: {
|
||||
RAILS_ENV: 'development',
|
||||
ActiveMapper: {
|
||||
id: 10,
|
||||
name: 'Connor',
|
||||
|
|
|
@ -67,7 +67,7 @@ const Cable = {
|
|||
})
|
||||
}
|
||||
$.ajax({
|
||||
url: '/main/synapses/' + event.synapse.id + '.json',
|
||||
url: '/synapses/' + event.synapse.id + '.json',
|
||||
success: function(response) {
|
||||
DataModel.Synapses.add(response)
|
||||
synapse = DataModel.Synapses.get(response.id)
|
||||
|
@ -77,7 +77,7 @@ const Cable = {
|
|||
}
|
||||
})
|
||||
$.ajax({
|
||||
url: '/main/mappings/' + event.mapping_id + '.json',
|
||||
url: '/mappings/' + event.mapping_id + '.json',
|
||||
success: function(response) {
|
||||
DataModel.Mappings.add(response)
|
||||
mapping = DataModel.Mappings.get(response.id)
|
||||
|
@ -149,7 +149,7 @@ const Cable = {
|
|||
})
|
||||
}
|
||||
$.ajax({
|
||||
url: '/main/topics/' + event.topic.id + '.json',
|
||||
url: '/topics/' + event.topic.id + '.json',
|
||||
success: function(response) {
|
||||
DataModel.Topics.add(response)
|
||||
topic = DataModel.Topics.get(response.id)
|
||||
|
@ -159,7 +159,7 @@ const Cable = {
|
|||
}
|
||||
})
|
||||
$.ajax({
|
||||
url: '/main/mappings/' + event.mapping_id + '.json',
|
||||
url: '/mappings/' + event.mapping_id + '.json',
|
||||
success: function(response) {
|
||||
DataModel.Mappings.add(response)
|
||||
mapping = DataModel.Mappings.get(response.id)
|
||||
|
|
|
@ -147,7 +147,7 @@ const Create = {
|
|||
$.ajax({
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
url: '/main/user/updatemetacodes',
|
||||
url: '/user/updatemetacodes',
|
||||
data: mdata,
|
||||
success: function(data) {
|
||||
console.log('selected metacodes saved')
|
||||
|
@ -206,7 +206,7 @@ const Create = {
|
|||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
remote: {
|
||||
url: '/main/topics/autocomplete_topic?term=%QUERY',
|
||||
url: '/topics/autocomplete_topic?term=%QUERY',
|
||||
wildcard: '%QUERY'
|
||||
}
|
||||
})
|
||||
|
@ -296,7 +296,7 @@ const Create = {
|
|||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
remote: {
|
||||
url: '/main/search/synapses?term=%QUERY',
|
||||
url: '/search/synapses?term=%QUERY',
|
||||
wildcard: '%QUERY'
|
||||
}
|
||||
})
|
||||
|
@ -304,7 +304,7 @@ const Create = {
|
|||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
remote: {
|
||||
url: '/main/search/synapses?topic1id=%TOPIC1&topic2id=%TOPIC2',
|
||||
url: '/search/synapses?topic1id=%TOPIC1&topic2id=%TOPIC2',
|
||||
prepare: function(query, settings) {
|
||||
var self = Create.newSynapse
|
||||
if (Selected.Nodes.length < 2 && self.topic1id && self.topic2id) {
|
||||
|
|
|
@ -9,7 +9,7 @@ import InfoBox from '../Map/InfoBox'
|
|||
import Mapper from '../Mapper'
|
||||
|
||||
const Map = Backbone.Model.extend({
|
||||
urlRoot: '/main/maps',
|
||||
urlRoot: '/maps',
|
||||
blacklist: ['created_at', 'updated_at', 'created_at_clean', 'updated_at_clean', 'user_name', 'contributor_count', 'topic_count', 'synapse_count', 'topics', 'synapses', 'mappings', 'mappers'],
|
||||
toJSON: function(options) {
|
||||
return _.omit(this.attributes, this.blacklist)
|
||||
|
|
|
@ -4,7 +4,7 @@ try { Backbone.$ = window.$ } catch (err) {}
|
|||
import outdent from 'outdent'
|
||||
|
||||
const Mapper = Backbone.Model.extend({
|
||||
urlRoot: '/main/users',
|
||||
urlRoot: '/users',
|
||||
blacklist: ['created_at', 'updated_at', 'follows'],
|
||||
toJSON: function(options) {
|
||||
return _.omit(this.attributes, this.blacklist)
|
||||
|
|
|
@ -5,7 +5,7 @@ import Mapper from './Mapper'
|
|||
|
||||
const MapperCollection = Backbone.Collection.extend({
|
||||
model: Mapper,
|
||||
url: '/main/users'
|
||||
url: '/users'
|
||||
})
|
||||
|
||||
export default MapperCollection
|
||||
|
|
|
@ -8,7 +8,7 @@ import Synapse from '../Synapse'
|
|||
import Topic from '../Topic'
|
||||
|
||||
const Mapping = Backbone.Model.extend({
|
||||
urlRoot: '/main/mappings',
|
||||
urlRoot: '/mappings',
|
||||
blacklist: ['created_at', 'updated_at'],
|
||||
toJSON: function(options) {
|
||||
return _.omit(this.attributes, this.blacklist)
|
||||
|
|
|
@ -5,7 +5,7 @@ import Mapping from './Mapping'
|
|||
|
||||
const MappingCollection = Backbone.Collection.extend({
|
||||
model: Mapping,
|
||||
url: '/main/mappings'
|
||||
url: '/mappings'
|
||||
})
|
||||
|
||||
export default MappingCollection
|
||||
|
|
|
@ -3,7 +3,7 @@ import Backbone from 'backbone'
|
|||
try { Backbone.$ = window.$ } catch (err) {}
|
||||
|
||||
const Message = Backbone.Model.extend({
|
||||
urlRoot: '/main/messages',
|
||||
urlRoot: '/messages',
|
||||
blacklist: ['created_at', 'updated_at'],
|
||||
toJSON: function(options) {
|
||||
return _.omit(this.attributes, this.blacklist)
|
||||
|
|
|
@ -5,7 +5,7 @@ import Message from './Message'
|
|||
|
||||
const MessageCollection = Backbone.Collection.extend({
|
||||
model: Message,
|
||||
url: '/main/messages'
|
||||
url: '/messages'
|
||||
})
|
||||
|
||||
export default MessageCollection
|
||||
|
|
|
@ -5,7 +5,7 @@ import Metacode from './Metacode'
|
|||
|
||||
const MetacodeCollection = Backbone.Collection.extend({
|
||||
model: Metacode,
|
||||
url: '/main/metacodes',
|
||||
url: '/metacodes',
|
||||
comparator: function(a, b) {
|
||||
a = a.get('name').toLowerCase()
|
||||
b = b.get('name').toLowerCase()
|
||||
|
|
|
@ -11,7 +11,7 @@ import Visualize from '../Visualize'
|
|||
import DataModel from './index'
|
||||
|
||||
const Synapse = Backbone.Model.extend({
|
||||
urlRoot: '/main/synapses',
|
||||
urlRoot: '/synapses',
|
||||
blacklist: ['edge', 'created_at', 'updated_at'],
|
||||
toJSON: function(options) {
|
||||
return _.omit(this.attributes, this.blacklist)
|
||||
|
|
|
@ -5,7 +5,7 @@ import Synapse from './Synapse'
|
|||
|
||||
const SynapseCollection = Backbone.Collection.extend({
|
||||
model: Synapse,
|
||||
url: '/main/synapses'
|
||||
url: '/synapses'
|
||||
})
|
||||
|
||||
export default SynapseCollection
|
||||
|
|
|
@ -10,7 +10,7 @@ import Visualize from '../Visualize'
|
|||
import DataModel from './index'
|
||||
|
||||
const Topic = Backbone.Model.extend({
|
||||
urlRoot: '/main/topics',
|
||||
urlRoot: '/topics',
|
||||
blacklist: ['node', 'created_at', 'updated_at', 'user_name', 'user_image', 'map_count', 'synapse_count'],
|
||||
toJSON: function(options) {
|
||||
return _.omit(this.attributes, this.blacklist)
|
||||
|
|
|
@ -5,7 +5,7 @@ import Topic from './Topic'
|
|||
|
||||
const TopicCollection = Backbone.Collection.extend({
|
||||
model: Topic,
|
||||
url: '/main/topics'
|
||||
url: '/topics'
|
||||
})
|
||||
|
||||
export default TopicCollection
|
||||
|
|
|
@ -9,7 +9,7 @@ const Notifications = {
|
|||
},
|
||||
fetch: render => {
|
||||
$.ajax({
|
||||
url: '/main/notifications.json',
|
||||
url: '/notifications.json',
|
||||
success: function(data) {
|
||||
Notifications.notifications = data
|
||||
render()
|
||||
|
@ -27,7 +27,7 @@ const Notifications = {
|
|||
markAsRead: (render, id) => {
|
||||
const n = Notifications.notifications.find(n => n.id === id)
|
||||
$.ajax({
|
||||
url: `/main/notifications/${id}/mark_read.json`,
|
||||
url: `/notifications/${id}/mark_read.json`,
|
||||
method: 'PUT',
|
||||
success: function(r) {
|
||||
if (n) {
|
||||
|
@ -44,7 +44,7 @@ const Notifications = {
|
|||
markAsUnread: (render, id) => {
|
||||
const n = Notifications.notifications.find(n => n.id === id)
|
||||
$.ajax({
|
||||
url: `/main/notifications/${id}/mark_unread.json`,
|
||||
url: `/notifications/${id}/mark_unread.json`,
|
||||
method: 'PUT',
|
||||
success: function() {
|
||||
if (n) {
|
||||
|
|
|
@ -68,7 +68,7 @@ const Search = {
|
|||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
remote: {
|
||||
url: '/main/search/topics',
|
||||
url: '/search/topics',
|
||||
prepare: function(query, settings) {
|
||||
settings.url += '?term=' + query
|
||||
if (Active.Mapper && self.limitTopicsToMe) {
|
||||
|
@ -101,7 +101,7 @@ const Search = {
|
|||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
remote: {
|
||||
url: '/main/search/maps',
|
||||
url: '/search/maps',
|
||||
prepare: function(query, settings) {
|
||||
settings.url += '?term=' + query
|
||||
if (Active.Mapper && self.limitMapsToMe) {
|
||||
|
@ -135,7 +135,7 @@ const Search = {
|
|||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
remote: {
|
||||
url: '/main/search/mappers?term=%QUERY',
|
||||
url: '/search/mappers?term=%QUERY',
|
||||
wildcard: '%QUERY'
|
||||
}
|
||||
})
|
||||
|
|
|
@ -370,7 +370,7 @@ const Import = {
|
|||
{
|
||||
success: function(topic) {
|
||||
if (topic.get('name') !== 'Link') return
|
||||
$.get('/main/hacks/load_url_title', {
|
||||
$.get('/hacks/load_url_title', {
|
||||
url
|
||||
}, function success(data, textStatus) {
|
||||
if (typeof data === 'string' && data.trim() === '') return
|
||||
|
|
|
@ -213,7 +213,7 @@ const InfoBox = {
|
|||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
remote: {
|
||||
url: '/main/search/mappers?term=%QUERY',
|
||||
url: '/search/mappers?term=%QUERY',
|
||||
wildcard: '%QUERY'
|
||||
}
|
||||
})
|
||||
|
@ -237,7 +237,7 @@ const InfoBox = {
|
|||
var self = InfoBox
|
||||
DataModel.Collaborators.remove(DataModel.Collaborators.get(collaboratorId))
|
||||
var mapperIds = DataModel.Collaborators.models.map(function(mapper) { return mapper.id })
|
||||
$.post('/main/maps/' + Active.Map.id + '/access', { access: mapperIds })
|
||||
$.post('/maps/' + Active.Map.id + '/access', { access: mapperIds })
|
||||
self.updateNumbers()
|
||||
},
|
||||
addCollaborator: function(newCollaboratorId) {
|
||||
|
@ -251,13 +251,13 @@ const InfoBox = {
|
|||
function callback(mapper) {
|
||||
DataModel.Collaborators.add(mapper)
|
||||
var mapperIds = DataModel.Collaborators.models.map(function(mapper) { return mapper.id })
|
||||
$.post('/main/maps/' + Active.Map.id + '/access', { access: mapperIds })
|
||||
$.post('/maps/' + Active.Map.id + '/access', { access: mapperIds })
|
||||
var name = DataModel.Collaborators.get(newCollaboratorId).get('name')
|
||||
GlobalUI.notifyUser(name + ' will be notified')
|
||||
self.updateNumbers()
|
||||
}
|
||||
|
||||
$.getJSON('/main/users/' + newCollaboratorId + '.json', callback)
|
||||
$.getJSON('/users/' + newCollaboratorId + '.json', callback)
|
||||
},
|
||||
handleResultClick: function(event, item) {
|
||||
var self = InfoBox
|
||||
|
|
|
@ -63,7 +63,7 @@ const Map = {
|
|||
self.setAccessRequest()
|
||||
const mapId = Active.Map.id
|
||||
$.post({
|
||||
url: `/main/maps/${mapId}/access_request`
|
||||
url: `/maps/${mapId}/access_request`
|
||||
})
|
||||
GlobalUI.notifyUser('Map creator will be notified of your request')
|
||||
},
|
||||
|
@ -117,7 +117,7 @@ const Map = {
|
|||
else {
|
||||
Loading.show()
|
||||
$.ajax({
|
||||
url: '/main/maps/' + id + '/contains.json',
|
||||
url: '/maps/' + id + '/contains.json',
|
||||
success: function(data) {
|
||||
Active.Map = new DataModelMap(data.map)
|
||||
DataModel.Mappers = new DataModel.MapperCollection(data.mappers)
|
||||
|
@ -153,7 +153,7 @@ const Map = {
|
|||
var self = Map
|
||||
|
||||
if (!Active.Map) return
|
||||
$.post('/main/maps/' + Active.Map.id + '/star')
|
||||
$.post('/maps/' + Active.Map.id + '/star')
|
||||
DataModel.Stars.push({ user_id: Active.Mapper.id, map_id: Active.Map.id })
|
||||
DataModel.Maps.Starred.add(Active.Map)
|
||||
GlobalUI.notifyUser('Map is now starred')
|
||||
|
@ -164,7 +164,7 @@ const Map = {
|
|||
var self = Map
|
||||
|
||||
if (!Active.Map) return
|
||||
$.post('/main/maps/' + Active.Map.id + '/unstar')
|
||||
$.post('/maps/' + Active.Map.id + '/unstar')
|
||||
DataModel.Stars = DataModel.Stars.filter(function(s) { return s.user_id !== Active.Mapper.id })
|
||||
DataModel.Maps.Starred.remove(Active.Map)
|
||||
self.mapIsStarred = false
|
||||
|
@ -263,7 +263,7 @@ const Map = {
|
|||
$.ajax({
|
||||
type: 'PATCH',
|
||||
dataType: 'json',
|
||||
url: `/main/maps/${Active.Map.id}`,
|
||||
url: `/maps/${Active.Map.id}`,
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
|
|
|
@ -7,7 +7,7 @@ const Mapper = {
|
|||
// @param id = the id of the mapper to retrieve
|
||||
get: function(id, callback) {
|
||||
$.ajax({
|
||||
url: `/main/users/${id}.json`,
|
||||
url: `/users/${id}.json`,
|
||||
success: data => {
|
||||
callback(new DataModel.Mapper(data))
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ export const acceptCall = self => userid => {
|
|||
invited: Active.Mapper.id,
|
||||
inviter: userid
|
||||
})
|
||||
$.post('/main/maps/' + Active.Map.id + '/events/conversation')
|
||||
$.post('/maps/' + Active.Map.id + '/events/conversation')
|
||||
self.joinCall()
|
||||
GlobalUI.clearNotify()
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ const Synapse = {
|
|||
// if the desired topic is not yet in the local topic repository, fetch it
|
||||
if (DataModel.Synapses.get(id) === undefined) {
|
||||
$.ajax({
|
||||
url: '/main/synapses/' + id + '.json',
|
||||
url: '/synapses/' + id + '.json',
|
||||
success: function(data) {
|
||||
DataModel.Synapses.add(data)
|
||||
callback(DataModel.Synapses.get(id))
|
||||
|
|
|
@ -85,7 +85,7 @@ const SynapseCard = {
|
|||
$('#edit_synapse_desc').attr('data-bip-attribute', 'desc')
|
||||
$('#edit_synapse_desc').attr('data-bip-type', 'textarea')
|
||||
$('#edit_synapse_desc').attr('data-bip-nil', dataNil)
|
||||
$('#edit_synapse_desc').attr('data-bip-url', '/main/synapses/' + synapse.id)
|
||||
$('#edit_synapse_desc').attr('data-bip-url', '/synapses/' + synapse.id)
|
||||
$('#edit_synapse_desc').attr('data-bip-value', synapse.get('desc'))
|
||||
$('#edit_synapse_desc').html(synapse.get('desc'))
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ const Topic = {
|
|||
// if the desired topic is not yet in the local topic repository, fetch it
|
||||
if (DataModel.Topics.get(id) === undefined) {
|
||||
$.ajax({
|
||||
url: '/main/topics/' + id + '.json',
|
||||
url: '/topics/' + id + '.json',
|
||||
success: function(data) {
|
||||
DataModel.Topics.add(data)
|
||||
callback(DataModel.Topics.get(id))
|
||||
|
@ -55,7 +55,7 @@ const Topic = {
|
|||
else {
|
||||
Loading.show()
|
||||
$.ajax({
|
||||
url: '/main/topics/' + id + '/network.json',
|
||||
url: '/topics/' + id + '/network.json',
|
||||
success: function(data) {
|
||||
Active.Topic = new DataModel.Topic(data.topic)
|
||||
DataModel.Creators = new DataModel.MapperCollection(data.creators)
|
||||
|
@ -90,7 +90,7 @@ const Topic = {
|
|||
onTopicFollow: topic => {
|
||||
const isFollowing = topic.isFollowedBy(Active.Mapper)
|
||||
$.post({
|
||||
url: `/main/topics/${topic.id}/${isFollowing ? 'un' : ''}follow`
|
||||
url: `/topics/${topic.id}/${isFollowing ? 'un' : ''}follow`
|
||||
})
|
||||
if (isFollowing) {
|
||||
GlobalUI.notifyUser('You are no longer following this topic')
|
||||
|
@ -166,7 +166,7 @@ const Topic = {
|
|||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '/main/topics/' + topic.id + '/relatives.json?' + paramsString,
|
||||
url: '/topics/' + topic.id + '/relatives.json?' + paramsString,
|
||||
success: successCallback,
|
||||
error: function() {}
|
||||
})
|
||||
|
|
|
@ -98,7 +98,7 @@ const ContextMenu = {
|
|||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: `/main/topics/${id}/relative_numbers.json?network=${topicsString}`,
|
||||
url: `/topics/${id}/relative_numbers.json?network=${topicsString}`,
|
||||
success: successCallback,
|
||||
error: function() {}
|
||||
})
|
||||
|
|
|
@ -109,7 +109,7 @@ const ExploreMaps = {
|
|||
|
||||
// first load the mapper object and then call the render function
|
||||
$.ajax({
|
||||
url: '/main/users/' + self.collection.mapperId + '/details.json',
|
||||
url: '/users/' + self.collection.mapperId + '/details.json',
|
||||
success: function(response) {
|
||||
self.mapper = response
|
||||
document.title = self.mapper.name + ' | Metamaps'
|
||||
|
@ -122,7 +122,7 @@ const ExploreMaps = {
|
|||
})
|
||||
},
|
||||
onStar: function(map) {
|
||||
$.post('/main/maps/' + map.id + '/star')
|
||||
$.post('/maps/' + map.id + '/star')
|
||||
map.set('star_count', map.get('star_count') + 1)
|
||||
if (DataModel.Stars) DataModel.Stars.push({ user_id: Active.Mapper.id, map_id: map.id })
|
||||
DataModel.Maps.Starred.add(map)
|
||||
|
@ -131,14 +131,14 @@ const ExploreMaps = {
|
|||
},
|
||||
onRequest: function(map) {
|
||||
$.post({
|
||||
url: `/main/maps/${map.id}/access_request`
|
||||
url: `/maps/${map.id}/access_request`
|
||||
})
|
||||
GlobalUI.notifyUser('You will be notified by email if request accepted')
|
||||
},
|
||||
onMapFollow: function(map) {
|
||||
const isFollowing = map.isFollowedBy(Active.Mapper)
|
||||
$.post({
|
||||
url: `/main/maps/${map.id}/${isFollowing ? 'un' : ''}follow`
|
||||
url: `/maps/${map.id}/${isFollowing ? 'un' : ''}follow`
|
||||
})
|
||||
if (isFollowing) {
|
||||
GlobalUI.notifyUser('You are no longer following this map')
|
||||
|
|
Loading…
Reference in a new issue