Skip to content

Commit 5018e0f

Browse files
committed
Migrate server to typescript
1 parent 1a416a3 commit 5018e0f

12 files changed

+254
-45
lines changed

.vscode/launch.json

+18
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@
1515
"request": "launch",
1616
"name": "Auth",
1717
"program": "${workspaceFolder}\\server\\gmail\\index.js"
18+
},
19+
{
20+
"type": "node",
21+
"request": "launch",
22+
"name": "Launch current file w/ ts-node",
23+
"protocol": "inspector",
24+
"args": [
25+
"${relativeFile}"
26+
],
27+
"cwd": "${workspaceRoot}",
28+
"runtimeArgs": [
29+
"-r",
30+
"ts-node/register"
31+
],
32+
"env": {
33+
"TS_NODE_COMPILER_OPTIONS": "{\"lib\": [\"ES2015\"]}"
34+
},
35+
"internalConsoleOptions": "openOnSessionStart"
1836
}
1937
]
2038
}

package-lock.json

+155
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
"@emotion/styled": "^10.0.5",
1616
"@material-ui/core": "^3.8.1",
1717
"@material-ui/icons": "^3.0.1",
18+
"@types/body-parser": "^1.17.0",
19+
"@types/es6-promise": "^3.3.0",
20+
"@types/express": "^4.16.0",
21+
"@types/express-session": "^1.15.11",
22+
"@types/mongodb": "^3.1.18",
23+
"@types/winston": "^2.4.4",
1824
"express": "^4.16.4",
1925
"express-session": "^1.15.6",
2026
"google-auth-library": "^2.0.2",
@@ -38,11 +44,14 @@
3844
"@babel/core": "^7.2.2",
3945
"@babel/preset-env": "^7.2.3",
4046
"@babel/preset-react": "^7.0.0",
47+
"@types/node": "^10.12.18",
4148
"babel-loader": "^8.0.4",
4249
"css-loader": "^2.1.0",
4350
"node-sass": "^4.11.0",
4451
"sass-loader": "^7.1.0",
4552
"style-loader": "^0.23.1",
53+
"ts-node": "^7.0.1",
54+
"typescript": "^3.2.2",
4655
"webpack": "^4.28.2",
4756
"webpack-cli": "^3.1.2"
4857
}

server/HelloWorld.js

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/HelloWorld.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/HelloWorld.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Startup {
2+
public static main(): number {
3+
console.log('Hello World');
4+
return 0;
5+
}
6+
}
7+
8+
Startup.main();

server/apiRouter.js server/apiRouter.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const { Router } = require("express")
2-
const DatabaseClient = require("./mongo-client")
3-
const stringifyObject = require('stringify-object');
1+
import { Router } from "express"
2+
// const DatabaseClient = require("./mongo-client")
3+
// const stringifyObject = require('stringify-object');
44

55
const apiRouter = Router();
6-
const client = new DatabaseClient();
6+
// const client = new DatabaseClient();
77
let logger;
88

9-
const withErrorHandler = (action) => {
9+
const withErrorHandler = (res, action) => {
1010
try {
1111
action();
1212
}
@@ -37,27 +37,27 @@ function router(loggerInstance) {
3737
apiRouter.get("/tasks",
3838
// TODO: paging?
3939
async (req, res) => {
40-
withErrorHandler(async () => {
41-
const tasks = await client.getTasks()
42-
res.send(JSON.stringify(tasks));
40+
withErrorHandler(res, async () => {
41+
// const tasks = await client.getTasks()
42+
// res.send(JSON.stringify(tasks));
4343
});
4444
});
4545

4646
apiRouter.get("/tasks/:id",
4747
async (req, res) => {
48-
withErrorHandler(async () => {
48+
withErrorHandler(res, async () => {
4949
const { id } = req.params
50-
const task = await client.getTask(id)
51-
res.send(JSON.stringify(task));
50+
// const task = await client.getTask(id)
51+
// res.send(JSON.stringify(task));
5252
});
5353
});
5454

5555
apiRouter.post("/tasks",
5656
async (req, res) => {
57-
withErrorHandler(async () => {
57+
withErrorHandler(res, async () => {
5858
const task = req.body;
59-
const createdTask = await client.insertTask(task)
60-
res.send(JSON.stringify(createdTask));
59+
// const createdTask = await client.insertTask(task)
60+
// res.send(JSON.stringify(createdTask));
6161
})
6262
});
6363

@@ -69,4 +69,4 @@ function router(loggerInstance) {
6969
return apiRouter
7070
}
7171

72-
module.exports = router
72+
export default router

0 commit comments

Comments
 (0)