Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to support swagger-ui-express #5

Closed
dsmileyephe opened this issue Jul 31, 2019 · 2 comments
Closed

Refactor to support swagger-ui-express #5

dsmileyephe opened this issue Jul 31, 2019 · 2 comments

Comments

@dsmileyephe
Copy link
Contributor

dsmileyephe commented Jul 31, 2019

Add swagger-ui-express to package.json
Refactor index.ts as follows:

// IMPORTANT: all routes that do not require JWT authentication must be declared ahead of registering the middleware with app.use
app.get('/', cors(), function (req, res) {
    res.status(200).send('Hello World! I am the tenants-api API ' +  process.env.API_VERSION);
});

const xssConfig = {
    stripIgnoreTag: true
};
app.use('/', new XSSController(xssConfig).register());

//setup route for documents
app.use('/docs/', cors(), swaggerUi.serveWithOptions({ redirect: false }), swaggerUi.setup(swaggerDocument));

Note what we are doing here is removing JWT validation from the health check and docs route.
Add boiler plate to the serverless yaml for the docs and health check:

HealthCheck:
        handler: src/index.handler
        events:
            - http:
                path: /
                method: get
                cors:
                    origin: '*'
                    headers:
                      - Content-Type
                      - Authorization
                      - x-amzn-trace-id
        warmup: true
        environment:
            STAGE: ${opt:stage}
            JWT_SECRET: ${opt:jwt-secret}
        vpc:
          securityGroupIds:
            - !ImportValue ${opt:networking-stack,'Zeus1-VPC'}:SecurityGroup
          subnetIds:
            - !ImportValue ${opt:networking-stack,'Zeus1-VPC'}:PrivateSubnet1
            - !ImportValue ${opt:networking-stack,'Zeus1-VPC'}:PrivateSubnet2
            - !ImportValue ${opt:networking-stack,'Zeus1-VPC'}:PrivateSubnet3
    Docs:
        handler: src/index.handler
        events:
            - http:
                path: /docs/{proxy+}
                method: get
                cors:
                    origin: '*'
                    headers:
                      - Content-Type
                      - Authorization
                      - x-amzn-trace-id
        warmup: true
        environment:
            STAGE: ${opt:stage}
            JWT_SECRET: ${opt:jwt-secret}
        vpc:
          securityGroupIds:
            - !ImportValue ${opt:networking-stack,'Zeus1-VPC'}:SecurityGroup
          subnetIds:
            - !ImportValue ${opt:networking-stack,'Zeus1-VPC'}:PrivateSubnet1
            - !ImportValue ${opt:networking-stack,'Zeus1-VPC'}:PrivateSubnet2
            - !ImportValue ${opt:networking-stack,'Zeus1-VPC'}:PrivateSubnet3
@dsmileyephe
Copy link
Contributor Author

Note {proxy+} is a catch all for routes exposed by API Gateway and allows the static files for swagger ui to be served.

@doriansmiley
Copy link
Owner

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants