Skip to content

Commit

Permalink
feat: use Location and X-Max-Bytes headers for POST response
Browse files Browse the repository at this point in the history
BREAKING CHANGE POST / no longer returns JSON
  • Loading branch information
hughns committed Sep 7, 2022
1 parent a49a0b5 commit 02e37dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Rendezvous } from './rendezvous';
import { maxBytes, ttlSeconds, port } from './config';

const app = express();
app.use(cors({ exposedHeaders: ['ETag'] }));
app.use(cors({ exposedHeaders: ['ETag', 'Location'] }));
app.use(morgan('common'));
app.set('env', 'production');
app.set('x-powered-by', false);
Expand Down Expand Up @@ -56,7 +56,10 @@ app.post('/', (req, res) => {

rv.setHeaders(res);

return res.status(200).json(rv.json());
res.setHeader('Location', id);
res.setHeader('X-Max-Bytes', maxBytes);

return res.sendStatus(201);
});

app.put('/:id', (req, res) => {
Expand Down
9 changes: 0 additions & 9 deletions src/rendezvous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
import express from 'express';
import { createHash } from 'crypto';

import { maxBytes } from './config';

export class Rendezvous {
private readonly id: string;
private readonly expiresAt: Date;
Expand Down Expand Up @@ -68,11 +66,4 @@ export class Rendezvous {
res.setHeader('Expires', this.expiresAt.toUTCString());
res.setHeader('Last-Modified', this.lastModified.toUTCString());
}

json() {
return {
id: this.id,
max_bytes: maxBytes,
};
}
}

0 comments on commit 02e37dc

Please sign in to comment.