Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Khalid Ali
schedules
Commits
49b66f05
Commit
49b66f05
authored
May 11, 2018
by
Zac Wood
Browse files
Deal with CORS in a less hacky way
parent
459ba299
Changes
5
Hide whitespace changes
Inline
Side-by-side
schedules_api/Gemfile
View file @
49b66f05
...
...
@@ -53,7 +53,7 @@ end
gem
'tzinfo-data'
,
platforms:
[
:mingw
,
:mswin
,
:x64_mingw
,
:jruby
]
gem
'httparty'
gem
'icalendar'
gem
'nokogiri'
gem
'rack-cors'
,
require:
'rack/cors'
gem
'rubyXL'
gem
'icalendar'
schedules_api/Gemfile.lock
View file @
49b66f05
...
...
@@ -96,6 +96,7 @@ GEM
public_suffix (3.0.2)
puma (3.11.3)
rack (2.0.4)
rack-cors (1.0.2)
rack-test (1.0.0)
rack (>= 1.0, < 3)
rails (5.1.6)
...
...
@@ -193,6 +194,7 @@ DEPENDENCIES
pry
pry-doc
puma (~> 3.7)
rack-cors
rails (~> 5.1.6)
rubyXL
sass-rails (~> 5.0)
...
...
schedules_api/app/controllers/calendar_generator_controller.rb
View file @
49b66f05
...
...
@@ -4,9 +4,8 @@ require 'time'
class
CalendarGeneratorController
<
ApplicationController
def
generate
cal
=
Icalendar
::
Calendar
.
new
posted_crns
=
JSON
.
parse
(
request
.
body
.
read
)
p
osted_crns
.
each
do
|
crn
|
p
arams
[
:_json
]
.
each
do
|
crn
|
section
=
Section
.
find_by_crn
(
crn
)
event
=
generate_event_from_section
(
section
)
cal
.
add_event
(
event
)
...
...
schedules_api/config/application.rb
View file @
49b66f05
...
...
@@ -14,8 +14,13 @@ module Schedules
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config
.
action_dispatch
.
default_headers
=
{
'Access-Control-Allow-Origin'
=>
'*'
}
# allow GET, POST or OPTIONS requests from any origin on any resource
config
.
middleware
.
insert_before
0
,
Rack
::
Cors
do
allow
do
origins
'*'
resource
'*'
,
:headers
=>
:any
,
:methods
=>
[
:get
,
:post
,
:options
]
end
end
end
end
schedules_web/src/components/App.tsx
View file @
49b66f05
...
...
@@ -32,20 +32,23 @@ class App extends React.Component<any, State> {
}
addSectionToCurrentScheduleIfUnique
=
(
section
:
Section
)
=>
{
if
(
!
this
.
state
.
currentSchedule
.
find
(
s
ectionInSchedule
=>
section
===
sectionInSchedule
))
{
if
(
!
this
.
isS
ectionInSchedule
(
section
))
{
this
.
setState
({
currentSchedule
:
[...
this
.
state
.
currentSchedule
,
section
],
});
}
};
isSectionInSchedule
=
(
section
:
Section
)
=>
this
.
state
.
currentSchedule
.
find
(
sectionInSchedule
=>
section
===
sectionInSchedule
);
generateSchedule
=
()
=>
{
const
crns
=
this
.
state
.
currentSchedule
.
map
(
section
=>
section
.
crn
);
fetch
(
'
http://localhost:3000/api/generate
'
,
{
method
:
'
POST
'
,
body
:
JSON
.
stringify
(
crns
),
headers
:
{
'
Content-Type
'
:
'
text/plai
n
'
,
'
Content-Type
'
:
'
application/jso
n
'
,
},
})
.
then
(
response
=>
response
.
text
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment