drop /pacosako prefix on APIs and serve static files

This commit is contained in:
Jesse D. McDonald 2020-05-02 15:40:11 -05:00
parent a2d0bcc18f
commit 6766f53248
2 changed files with 35 additions and 20 deletions

View File

@ -88,7 +88,7 @@ The following data is stored in the database but not included in any REST API:
## REST APIs
### `GET /pacosako/api/games`
### `GET /api/games`
Returns the list of active games.
A game is considered "active" if the `timestamp` field indicates that
@ -104,7 +104,7 @@ The objects in the `games` array include
all of the game object fields described above
*except* the `board` field.
### `GET /pacosako/api/games/poll/:afterTime`
### `GET /api/games/poll/:afterTime`
Parameters:
@ -112,7 +112,7 @@ Parameters:
Any record with a `modified` field less than or equal to this value
is excluded from the results.
Equivalent to the `GET /pacosako/api/games` API with two exceptions.
Equivalent to the `GET /api/games` API with two exceptions.
First, it excludes games with older `modified` times from the results.
Second, if there are no results which match this criteria
then the server waits up to one minute for the situation to change
@ -124,9 +124,9 @@ then the server will respond immediately with the new information.
The `afterTime` parameter will normally match the `modified` field
from the most recent successful response to either
`GET /pacosako/api/games` or `GET /pacosako/api/games/poll/:afterTime`.
`GET /api/games` or `GET /api/games/poll/:afterTime`.
### `GET /pacosako/api/game/:gameId`
### `GET /api/game/:gameId`
Parameters:
@ -136,12 +136,12 @@ On success this API returns the complete game object for the given `gameId`,
which must be a 16-character hexadecimal string.
If there is no record matching the given gameId then a 404 status code is returned.
### `GET /pacosako/api/meta/:gameId`
### `GET /api/meta/:gameId`
This API is identical to `GET /pacosako/api/game/:gameId` except that the
This API is identical to `GET /api/game/:gameId` except that the
`board` field is omitted from the response.
### `GET /pacosako/api/game/:gameId/poll/:afterTime`
### `GET /api/game/:gameId/poll/:afterTime`
Parameters:
@ -150,7 +150,7 @@ Parameters:
* `afterTime`: Integer. The response must be a game object
with a `modified` field strictly greater than this value.
Equivalent to the `GET /pacosako/api/game/:gameId` API except that
Equivalent to the `GET /api/game/:gameId` API except that
if there is no record with a matching `gameId`
or the record has a `modified` field less than or equal to the `afterTime` parameter
then the server waits up to one minute for the situation to change
@ -163,14 +163,14 @@ this API does not return a 404 status code when the `gameId` does not exist.
The `afterTime` parameter will normally match the `modified` field
from the most recent successful response to either
`GET /pacosako/api/game/:gameId` or `GET /pacosako/api/game/:gameId/poll/:afterTime`.
`GET /api/game/:gameId` or `GET /api/game/:gameId/poll/:afterTime`.
### `GET /pacosako/api/meta/:gameId/poll/:afterTime`
### `GET /api/meta/:gameId/poll/:afterTime`
This API is identical to `GET /pacosako/api/game/:gameId/poll/:afterTime`
This API is identical to `GET /api/game/:gameId/poll/:afterTime`
except that the `board` field is omitted from the response.
### `POST /pacosako/api/game/:gameId`
### `POST /api/game/:gameId`
Parameters:
@ -202,7 +202,15 @@ Otherwise the POST request succeeds with a status code of 200
and the response body consists of a `success` field with the value `true`
and the `modified` field of the new version of the record.
### `POST /pacosako/api/meta/:gameId`
### `POST /api/meta/:gameId`
This is an alias for the `POST /pacosako/api/game/:gameId` API.
This is an alias for the `POST /api/game/:gameId` API.
Either API can be used to update any field, including `board`.
## Static Files
If a directory named `public` exists in the current directory
then the contents of the `public` directory are served as static files
for any request which does not match one of the REST APIs listed above.
This allows this package to serve as a standalone server for both the REST APIs
and any client-side resources.

View File

@ -431,12 +431,19 @@ const app = express();
app.use(cors());
app.get('/pacosako/api/games/poll/:afterTime', catchExceptionsJson(getGameListHandler));
app.get('/pacosako/api/games', catchExceptionsJson(getGameListHandler));
app.get('/api/games/poll/:afterTime', catchExceptionsJson(getGameListHandler));
app.get('/api/games', catchExceptionsJson(getGameListHandler));
app.get('/pacosako/api/:type(game|meta)/:gameId/poll/:afterTime', catchExceptionsJson(getGameHandler));
app.get('/pacosako/api/:type(game|meta)/:gameId', catchExceptionsJson(getGameHandler));
app.post('/pacosako/api/:type(game|meta)/:gameId', express.json(), catchExceptionsJson(postGameHandler));
app.get('/api/:type(game|meta)/:gameId/poll/:afterTime', catchExceptionsJson(getGameHandler));
app.get('/api/:type(game|meta)/:gameId', catchExceptionsJson(getGameHandler));
app.post('/api/:type(game|meta)/:gameId', express.json(), catchExceptionsJson(postGameHandler));
if (fs.statSync('public').isDirectory()) {
app.use(express.static('public', {
fallthrough: false,
maxAge: 0,
}));
}
var config = { port: process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765 };