Skip to content

Commit

Permalink
refactor: move register plugins to create server
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Aug 1, 2022
1 parent 6f03251 commit 5e101a6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
4 changes: 1 addition & 3 deletions src/ServerlessOffline.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ export default class ServerlessOffline {

this.#http = new Http(this.#serverless, this.#options, this.#lambda)

this.#http.createServer()

await this.#http.registerPlugins()
await this.#http.createServer()

this.#http.create(events)

Expand Down
8 changes: 2 additions & 6 deletions src/events/http/Http.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export default class Http {
return this.#httpServer.stop(timeout)
}

createServer() {
this.#httpServer.createServer()
async createServer() {
await this.#httpServer.createServer()
}

#createEvent(functionKey, rawHttpEventDefinition, handler) {
Expand All @@ -43,10 +43,6 @@ export default class Http {
this.#httpServer.create404Route()
}

registerPlugins() {
return this.#httpServer.registerPlugins()
}

// TEMP FIXME quick fix to expose gateway server for testing, look for better solution
getServer() {
return this.#httpServer.getServer()
Expand Down
16 changes: 7 additions & 9 deletions src/events/http/HttpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class HttpServer {
this.#serverless = serverless
}

createServer() {
async createServer() {
const {
enforceSecureCookies,
host,
Expand Down Expand Up @@ -90,6 +90,12 @@ export default class HttpServer {
// Hapijs server creation
this.#server = new Server(serverOptions)

try {
await this.#server.register([h2o2])
} catch (err) {
log.error(err)
}

// Enable CORS preflight response
this.#server.ext('onPreResponse', (request, h) => {
if (request.headers.origin) {
Expand Down Expand Up @@ -207,14 +213,6 @@ export default class HttpServer {
})
}

async registerPlugins() {
try {
await this.#server.register([h2o2])
} catch (err) {
log.error(err)
}
}

#logPluginIssue() {
log.notice(
'If you think this is an issue with the plugin please submit it, thanks!\nhttps://github.com/dherault/serverless-offline/issues',
Expand Down

0 comments on commit 5e101a6

Please sign in to comment.