Skip to content

Commit 1f4bd58

Browse files
andrewncatarak
authored andcommitted
Public API: Namespace private and public APIs (processing#1148)
* Converts import script to use public API endpoints The endpoints don't exist yet, but this is a good way to see how the implementation of the data structures differ. * Exposes public API endpoint to fetch user's sketches * Implements public API delete endpoint * Adds helper to create custom ApplicationError classes * Adds create project endpoint that understand API's data structure This transforms the nested tree of file data into a mongoose Project model * Returns '201 Created' to match API spec * Removes 'CustomError' variable assignment as it shows up in test output * transformFiles will return file validation errors * Tests API project controller * Tests toModel() * Creates default files if no root-level .html file is provided * Do not auto-generate a slug if it is provided Fixes a bug where the slug was auto-generated using the sketch name, even if a slug property had been provided. * Validates uniqueness of slugs for projects created by the public API * Adds tests for slug uniqueness * Configures node's Promise implementation for mongoose (fixes warnings) * Moves createProject tests to match controller location * Adds support for code to ApplicationErrors * deleteProject controller tests * getProjectsForUser controller tests - implements tests - update apiKey tests to use new User mocks * Ensure error objects have consistent property names `message` is used as a high-level description of the errors `detail` is optional and has an plain language explanation of the individual errors `errors` is an array of each individual problem from `detail` in a machine-readable format * Assert environment variables are provided at script start * Version public API * Expect "files" property to always be provided * Fixes linting error * Converts import script to use public API endpoints The endpoints don't exist yet, but this is a good way to see how the implementation of the data structures differ. * Exposes public API endpoint to fetch user's sketches * Implements public API delete endpoint * Adds helper to create custom ApplicationError classes * Adds create project endpoint that understand API's data structure This transforms the nested tree of file data into a mongoose Project model * Returns '201 Created' to match API spec * Removes 'CustomError' variable assignment as it shows up in test output * transformFiles will return file validation errors * Tests API project controller * Tests toModel() * Creates default files if no root-level .html file is provided * Do not auto-generate a slug if it is provided Fixes a bug where the slug was auto-generated using the sketch name, even if a slug property had been provided. * Validates uniqueness of slugs for projects created by the public API * Adds tests for slug uniqueness * Configures node's Promise implementation for mongoose (fixes warnings) * Moves createProject tests to match controller location * deleteProject controller tests * Adds support for code to ApplicationErrors * getProjectsForUser controller tests - implements tests - update apiKey tests to use new User mocks * Ensure error objects have consistent property names `message` is used as a high-level description of the errors `detail` is optional and has an plain language explanation of the individual errors `errors` is an array of each individual problem from `detail` in a machine-readable format * Assert environment variables are provided at script start * Version public API * Expect "files" property to always be provided * Fixes linting error * Checks that authenticated user has permission to create under this namespace Previously, the project was always created under the authenticated user's namespace, but this not obvious behaviour. * Splits private and public APIs The private API is under /editor and the public API under /api
1 parent d44a058 commit 1f4bd58

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
API_URL=/api
1+
API_URL=/editor
22
AWS_ACCESS_KEY=<your-aws-access-key>
33
AWS_REGION=<your-aws-region>
44
AWS_SECRET_KEY=<your-aws-secret-key>

app.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"env": {
1818
"API_URL": {
19-
"value": "/api"
19+
"value": "/editor"
2020
},
2121
"AWS_ACCESS_KEY": {
2222
"description": "AWS Access Key",

server/server.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,19 @@ app.use(session({
9797
app.use(passport.initialize());
9898
app.use(passport.session());
9999
app.use('/api/v1', requestsOfTypeJSON(), api);
100-
app.use('/api', requestsOfTypeJSON(), users);
101-
app.use('/api', requestsOfTypeJSON(), sessions);
102-
app.use('/api', requestsOfTypeJSON(), files);
103-
app.use('/api', requestsOfTypeJSON(), projects);
104-
app.use('/api', requestsOfTypeJSON(), aws);
100+
app.use('/editor', requestsOfTypeJSON(), users);
101+
app.use('/editor', requestsOfTypeJSON(), sessions);
102+
app.use('/editor', requestsOfTypeJSON(), files);
103+
app.use('/editor', requestsOfTypeJSON(), projects);
104+
app.use('/editor', requestsOfTypeJSON(), aws);
105105

106106
// This is a temporary way to test access via Personal Access Tokens
107107
// Sending a valid username:<personal-access-token> combination will
108108
// return the user's information.
109-
app.get('/api/auth/access-check', passport.authenticate('basic', { session: false }), (req, res) => res.json(req.user));
109+
app.get(
110+
'/api/v1/auth/access-check',
111+
passport.authenticate('basic', { session: false }), (req, res) => res.json(req.user)
112+
);
110113

111114
app.use(assetRoutes);
112115
// this is supposed to be TEMPORARY -- until i figure out

0 commit comments

Comments
 (0)