Skip to content

Commit 1f24b48

Browse files
committed
swagger docs generation integrated and moved to yarn
1 parent 3c6e21d commit 1f24b48

13 files changed

+3850
-12
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ WORKDIR /usr/app
44

55
COPY package.json .
66

7-
RUN npm install -g typescript typeorm gulp-cli
8-
RUN npm install --verbose
7+
RUN npm install -g typescript typeorm gulp-cli yarn
8+
RUN yarn install

api/controllers/MainController.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ export class MainController {
1919

2020
@Post("/login")
2121
async login(@Body() credentials: LoginBody) {
22-
const user = await User.findOne({ where: { email: credentials.email } })
2322

24-
let matches = await bcrypt.compare(credentials.password, user.password)
25-
if (!matches) {
23+
try {
24+
const user = await User.findOne({ where: { email: credentials.email } })
25+
let matches = await bcrypt.compare(credentials.password, user.password)
26+
if (!matches) {
27+
throw new Error()
28+
}
29+
let authToken = new AuthToken()
30+
authToken.user = user
31+
await authToken.save()
32+
return AuthToken.findOne({ token: authToken.token })
33+
} catch {
2634
throw new HttpError(400, "Credentials do not match")
2735
}
28-
let authToken = new AuthToken()
29-
authToken.user = user
30-
await authToken.save()
31-
return AuthToken.findOne({ token: authToken.token })
36+
3237
}
3338
}

api/server.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ import { routing } from './routing'
55
import * as express from 'express'
66
import * as http from 'http'
77

8+
const swaggerJson = require('../swagger.json')
9+
810
export const app = createExpressServer(routing)
911
const httpServer = http.createServer(app)
1012

13+
app.use('/swagger', express.static('swagger'))
14+
app.get('/docs', (req: any, res: any) => {
15+
res.send(swaggerJson)
16+
})
17+
1118
const postGresConfig: ConnectionOptions = {
1219
type: "postgres",
1320
url: process.env["DATABASE_URL"],
@@ -35,4 +42,4 @@ export async function stopServer() {
3542
await httpServer.close()
3643
}
3744
return Promise.resolve(undefined)
38-
}
45+
}

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"build": "rm -rf .build && tsc",
7+
"build": "rm -rf .build && npm run experimental-generate-docs && tsc",
88
"start": "npm run build && node .build/api/index.js",
99
"test": "npm run build && mocha .build/test/e2e/index.js",
1010
"resetdb": "npm run build && node .build/test/commands/resetdb.js",

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,22 @@ Work in progress template for cloning
1616

1717
## To-dos
1818

19+
- Swagger docs generation support
1920
- Fixtures for e2e testing
2021
- User CRUD
2122
- Password email reset
2223
- Email confirmation status
2324
- User creation via email reset flow (i.e. confirmation)
2425
- Device Authorization via email
2526

27+
28+
2629
- Todo Management
2730
- CRUD Todo List
2831
- CRUD Todo List Item
2932

3033
### Nice to have
3134

32-
- Swagger docs generation support
3335
- iOS Push Notification support
3436
- Google OAuth Signup
3537
- Facebook OAuth Signup

swagger/favicon-16x16.png

445 Bytes
Loading

swagger/favicon-32x32.png

1.11 KB
Loading

swagger/index.html

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!-- HTML for static distribution bundle build -->
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8">
6+
<title>Swagger UI</title>
7+
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
8+
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
9+
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
10+
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
11+
<style>
12+
html
13+
{
14+
box-sizing: border-box;
15+
overflow: -moz-scrollbars-vertical;
16+
overflow-y: scroll;
17+
}
18+
19+
*,
20+
*:before,
21+
*:after
22+
{
23+
box-sizing: inherit;
24+
}
25+
26+
body
27+
{
28+
margin:0;
29+
background: #fafafa;
30+
}
31+
</style>
32+
</head>
33+
34+
<body>
35+
<div id="swagger-ui"></div>
36+
37+
<script src="./swagger-ui-bundle.js"> </script>
38+
<script src="./swagger-ui-standalone-preset.js"> </script>
39+
<script>
40+
window.onload = function() {
41+
42+
// Build a system
43+
const ui = SwaggerUIBundle({
44+
url: "http://localhost:3000/docs",
45+
dom_id: '#swagger-ui',
46+
deepLinking: true,
47+
presets: [
48+
SwaggerUIBundle.presets.apis,
49+
SwaggerUIStandalonePreset
50+
],
51+
plugins: [
52+
SwaggerUIBundle.plugins.DownloadUrl
53+
],
54+
layout: "StandaloneLayout"
55+
})
56+
57+
window.ui = ui
58+
}
59+
</script>
60+
</body>
61+
</html>

swagger/swagger-ui-bundle.js

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)