Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ const endpoints = [
"retrieve_event"
];

// host each of those endpoint files at a php-like url:
// host each of those endpoint files:
// note: require() is synchronous.
endpoints.forEach((ep) => {
const apipath = `/api/${ep}.php`;
const apipath = `/api/${ep}`;
const endpoint = require(`./endpoints/${ep}.js`);
if (endpoint.get) {
app.get(apipath, endpoint.get);
Expand Down
4 changes: 2 additions & 2 deletions app/endpoints/crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Used by web crawlers such as search engines.
*
* Expects an (optional) TIME id using url query parameter; ex:
* https://api.shift2bikes.org/api/crawl.php?id=15229
* https://localhost:3080/api/crawl.php?id=1893
* https://api.shift2bikes.org/api/crawl?id=15229
* https://localhost:3080/api/crawl?id=1893
*
* See also:
* https://github.com/shift-org/shift-docs/blob/main/docs/CALENDAR_API.md#crawling-an-event
Expand Down
6 changes: 3 additions & 3 deletions app/endpoints/delete_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*
* You can use curl to post json for testing. For example:
* curl -k -H 'Content-Type: application/json' -X POST --data-binary \
* "@delete_event.json" https://localhost:4443/api/delete_event.php
* "@delete_event.json" https://localhost:4443/api/delete_event
* {
* "id": "6245",
* "secret": "example"
* }
*
* If there was an error ( for example, if the id was missing or the event wasn't found )
* returns http 400 "Bad Request" and a json error response (see errors.php)
* If there was an error (for example, if the id was missing or the event wasn't found)
* returns http 400 "Bad Request" and a json error response (see errors.js)
*
*/
const config = require("../config");
Expand Down
6 changes: 3 additions & 3 deletions app/endpoints/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* &all=true ( to include soft deleted rides )
*
* For example:
* http://localhost:3080/api/events.php?id=1893
* https://localhost:4443/api/events.php?startdate=2023-03-19&enddate=2023-03-29
* http://localhost:3080/api/events?id=1893
* https://localhost:4443/api/events?startdate=2023-03-19&enddate=2023-03-29
*
* In both cases it returns a list of events as a JSON object:
* {
Expand Down Expand Up @@ -146,5 +146,5 @@ function getEventRangeUrl(start, end) {
// the start and end, filtered through date formatting
// should be safe to use as is, otherwise see: encodeURIComponent()
return config.site.url("api",
`events.php?startdate=${startdate}&enddate=${enddate}`);
`events?startdate=${startdate}&enddate=${enddate}`); // 735-TODO: validate
}
12 changes: 5 additions & 7 deletions app/endpoints/ical.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* 'filename' customizes the name of the generated file ( the default name is in config.js. )
* ( the special name of "none" will not generate an attachment )
*
* https://localhost:4443/api/ical.php
* https://localhost:4443/api/ical.php?id=998
* https://localhost:4443/api/ical.php?startdate=2023-05-25&enddate=2023-06-25
* https://localhost:4443/api/ical.php?id=13&filename=triskaidekaphobia.ics
* https://localhost:4443/api/ical
* https://localhost:4443/api/ical?id=998
* https://localhost:4443/api/ical?startdate=2023-05-25&enddate=2023-06-25
* https://localhost:4443/api/ical?id=13&filename=triskaidekaphobia.ics
*
* See also:
* AllEvents.md
Expand Down Expand Up @@ -112,9 +112,7 @@ function getEventData(cal, id, start, end, includeDeleted) {
* @see https://datatracker.ietf.org/doc/html/rfc5545#section-3.6.1
*/
function respondWith(cal, res, filename, events) {
// note: the php sets includes utf8 in the content type but...
// according to https://en.wikipedia.org/wiki/ICalendar
// its default utf8, and mime type should be used for anything different.
// according to https://en.wikipedia.org/wiki/ICalendar its default utf8, and mime type should be used for anything different.
res.setHeader(config.api.header, config.api.version);
if (!filename || filename === "none") {
res.setHeader('content-type', `text/plain`);
Expand Down
2 changes: 1 addition & 1 deletion app/endpoints/manage_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* You can use curl to post some json for testing. For example:
* curl -k -H 'Content-Type: application/json' -X POST --data-binary \
* "@manageEvent.json" https://localhost:4443/api/manage_event.php
* "@manageEvent.json" https://localhost:4443/api/manage_event
*
* On success, it will return a summary of the events and its times.
* If there is a problem, it returns a set of 'fieldErrors' ( see errors.js )
Expand Down
8 changes: 3 additions & 5 deletions app/endpoints/retrieve_event.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* Expects an calevent id (and optionally, its matching secret) using url query parameters.
*
* For example:
* https://localhost:3080/api/retrieve_event.php?id=595&secret=12e1c433836d6c92431ac71f1ff6dd97
* https://localhost:3080/api/retrieve_event?id=595&secret=12e1c433836d6c92431ac71f1ff6dd97
*
* On success, returns a json summary of event.
* If there was an error ( for example, if the id was missing or the event wasn't found )
* returns http 400 "Bad Request" with a json error response ( see errors.php )
* If there was an error (for example, if the id was missing or the event wasn't found)
* returns http 400 "Bad Request" with a json error response ( see errors.js )
*
* See also:
* https://github.com/shift-org/shift-docs/blob/main/docs/CALENDAR_API.md#retrieving-public-event-data
Expand All @@ -31,8 +31,6 @@ exports.get = function get(req, res, next) {
} else if (evt.isDeleted()) {
res.textError("Event was deleted");
} else {
// the php version didnt error on invalid secret;
// so this doesnt either ( private data is only returned with a valid secret )
const includePrivate = evt.isSecretValid(secret);
if (!evt.isPublished() && !includePrivate) {
// act exactly as if unpublished events don't exist
Expand Down
2 changes: 1 addition & 1 deletion app/models/calDaily.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class CalDaily {
* @param statusMap a js Map containing {YYYY-MM-DD: dateStatus }
* @return the promise of valid CalDaily(s)
*
* @see: DateStatus.php, manage_event.php
* @see: dateStatus.js, manage_event.js
*/
static reconcile(evt, statusMap, softDelete = true) {
return CalDaily.getByEventID(evt.id).then((dailies) => {
Expand Down
2 changes: 1 addition & 1 deletion app/test/crawl_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("crawl testing", () => {
// test:
it("handles a simple get", function(done) {
chai.request( app )
.get('/api/crawl.php')
.get('/api/crawl.php') // 735-TODO: update tests and run specs
.end(function (err, res) {
expect(err).to.be.null;
expect(res).to.have.status(200);
Expand Down
29 changes: 25 additions & 4 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,42 @@

[[redirects]]
from = "/cal/icalpp.php"
to = "https://api.shift2bikes.org/api/pedalpalooza-calendar.php"
to = "https://api.shift2bikes.org/api/pedalpalooza-calendar"
status = 200
force = true

## the official pedalpalooza feed
[[redirects]]
from = "/cal/pedalpalooza-calendar.php"
to = "https://api.shift2bikes.org/api/pedalpalooza-calendar.php"
to = "https://api.shift2bikes.org/api/pedalpalooza-calendar"
status = 200
force = true

## the official "all events" feed.
[[redirects]]
from = "/cal/shift-calendar.php"
to = "https://api.shift2bikes.org/api/shift-calendar.php"
to = "https://api.shift2bikes.org/api/shift-calendar"
status = 200
force = true

## 735-TODO: these because app may try to reach these endpoints at www. instead of api. - can solve with regex combining with the above?
[[redirects]]
from = "/cal/icalpp"
to = "https://api.shift2bikes.org/api/pedalpalooza-calendar"
status = 200
force = true

## the official pedalpalooza feed
[[redirects]]
from = "/cal/pedalpalooza-calendar"
to = "https://api.shift2bikes.org/api/pedalpalooza-calendar"
status = 200
force = true

## the official "all events" feed.
[[redirects]]
from = "/cal/shift-calendar"
to = "https://api.shift2bikes.org/api/shift-calendar"
status = 200
force = true

Expand Down Expand Up @@ -132,7 +153,7 @@
to = "/pages/pedalpalooza"
status = 301

## old bike rack webpage linked from PBoT and other offsite pages we can't fix
## old bike rack webpage linked from PBoT and other offsite pages we can't fix
[[redirects]]
from = "/wiki/shift-shop:rack-rental"
to = "/pages/bike-racks/"
Expand Down
4 changes: 2 additions & 2 deletions netlify.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@

[[redirects]]
from = "/my/specialpath"
to = "https://api.primarydomain.org/api/pedalpalooza-calendar.php"
to = "https://api.primarydomain.org/api/pedalpalooza-calendar"
status = 200
force = true

## the official "all events" feed.
## you'll probably want this somewhere on your ite!
[[redirects]]
from = "/allevents"
to = "https://api.primarydomain.org/api/shift-calendar.php"
to = "https://api.primarydomain.org/api/shift-calendar"
status = 200
force = true

Expand Down
9 changes: 5 additions & 4 deletions services/nginx/conf.d/shift.conf
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,27 @@ server {

# used for the per-ride "export link".
# the client sends an id as a query parameter.
# 735-TODO: investigate use of .php in this file
location = /api/ics.php {
proxy_pass http://node:3080/api/ical.php;
proxy_pass http://node:3080/api/ical;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

# webcal endpoint for only pedalpalooza subscriptions:
# ex. webcal://www.shift2bikes.org/cal/pedalpalooza-calendar.php
location = /api/pedalpalooza-calendar.php {
# set to a constant range for this year's pedalp
proxy_pass http://node:3080/api/ical.php?startdate=2024-06-01&enddate=2024-08-31&filename=pedalpalooza-2024.ics;
proxy_pass http://node:3080/api/ical?startdate=2024-06-01&enddate=2024-08-31&filename=pedalpalooza-2024.ics;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

# webcal endpoint for that includes all shift events:
location = /api/shift-calendar.php {
proxy_pass http://node:3080/api/ical.php;
proxy_pass http://node:3080/api/ical;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

# note: app/app.js remaps incoming ".php" extensions to ".js" endpoints
# note: app/app.js remaps incoming ".php" extensions to ".js" endpoints // 735-TODO: update this comment
location /api/ {
# note the trailing slash on the proxy; that causes nginx to strip /api/ completely.
proxy_pass http://node:3080/api/;
Expand Down
1 change: 0 additions & 1 deletion site/themes/s2b_hugo_theme/assets/js/cal/addevent.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@
}
// munge the "file" errors to be "image" errors
// so that the error message shows on proper line.
// tbd: we also change this in manage_event.php
if (err.fields && err.fields.file && !err.fields.image) {
err.fields.image = err.fields.file;
}
Expand Down
10 changes: 5 additions & 5 deletions site/themes/s2b_hugo_theme/assets/js/cal/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ const SITE_TITLE = "Shift";
const API_VERSION = '3';

const API_BASE_URL = window.location.origin;
const API_EVENTS_URL = new URL('/api/events.php', API_BASE_URL);
const API_ICS_URL = new URL('/api/ics.php', API_BASE_URL);
const API_MANAGE_URL = new URL('/api/manage_event.php', API_BASE_URL);
const API_RETRIEVE_URL = new URL('/api/retrieve_event.php', API_BASE_URL);
const API_DELETE_URL = new URL('/api/delete_event.php', API_BASE_URL);
const API_EVENTS_URL = new URL('/api/events', API_BASE_URL);
const API_ICS_URL = new URL('/api/ics', API_BASE_URL);
const API_MANAGE_URL = new URL('/api/manage_event', API_BASE_URL);
const API_RETRIEVE_URL = new URL('/api/retrieve_event', API_BASE_URL);
const API_DELETE_URL = new URL('/api/delete_event', API_BASE_URL);

const API_HEADERS = {
'Accept': 'application/json',
Expand Down