Skip to content

Commit

Permalink
Merge pull request #159 from usegraffy/server-content-type
Browse files Browse the repository at this point in the history
Server content type
  • Loading branch information
aravindet authored May 7, 2024
2 parents 7e2c56a + 8934d00 commit 575c7e9
Show file tree
Hide file tree
Showing 4 changed files with 402 additions and 369 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: yarn install
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"homepage": "https://graffy.org",
"devDependencies": {
"@babel/preset-react": "^7.16.7",
"@biomejs/biome": "^1.5.3",
"@biomejs/biome": "^1.7.3",
"@faker-js/faker": "^8.4.1",
"@testing-library/react": "^15.0.0",
"@testing-library/react": "^15.0.6",
"@types/debug": "^4.1.7",
"@types/jest": "^29.5.12",
"@types/pg": "^8.6.5",
"@types/react": "^18.0.26",
"@types/pg": "^8.11.6",
"@types/react": "^18.3.1",
"@vitejs/plugin-react": "^4.2.1",
"debug": "^4.3.3",
"express": "^4.18.2",
Expand All @@ -44,16 +44,16 @@
"p-map": "^7.0.2",
"pg": "^8.7.1",
"prop-types": "^15.8.1",
"puppeteer": "^22.6.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-test-renderer": "^18.2.0",
"puppeteer": "^22.8.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-test-renderer": "^18.3.1",
"rimraf": "^5.0.5",
"sql-template-tag": "^5.0.3",
"sql-template-tag": "^5.2.1",
"typescript": "^5.4.5",
"uuid": "^9.0.0",
"vite": "^5.2.8",
"ws": "^8.11.0",
"vite": "^5.2.11",
"ws": "^8.17.0",
"yargs": "^17.6.2"
},
"peerDependencies": {
Expand Down
40 changes: 30 additions & 10 deletions src/server/httpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ export default function server(store, { auth } = {}) {
} catch (e) {
log(e.message);
log(e.stack);
res.writeHead(400);
res.end(`${e.message}`);
const body = `${e.message}`;
res.writeHead(400, {
'Content-Type': 'text/plain',
'Content-Length': Buffer.byteLength(body),
});
res.end(body);
}
} else if (req.method === 'POST') {
try {
Expand All @@ -79,23 +83,39 @@ export default function server(store, { auth } = {}) {
options,
))
) {
res.writeHead(401);
res.end('unauthorized');
const body = 'unauthorized';
res.writeHead(401, {
'Content-Type': 'text/plain',
'Content-Length': Buffer.byteLength(body),
});
res.end(body);
return;
}

const value = await store.call(op, payload, options);
res.writeHead(200);
res.end(JSON.stringify(pack(value)));
const body = JSON.stringify(pack(value));
res.writeHead(200, {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(body),
});
res.end(body);
} catch (e) {
log(e.message);
log(e.stack);
res.writeHead(400);
res.end(`${e.message}`);
const body = `${e.message}`;
res.writeHead(400, {
'Content-Type': 'text/plain',
'Content-Length': Buffer.byteLength(body),
});
res.end(body);
}
} else {
res.writeHead(501);
res.end('Not implemented');
const body = 'Not implemented';
res.writeHead(501, {
'Content-Type': 'text/plain',
'Content-Length': Buffer.byteLength(body),
});
res.end(body);
}
};
}
Loading

0 comments on commit 575c7e9

Please sign in to comment.