diff --git a/cors.js b/api/cors.js similarity index 100% rename from cors.js rename to api/cors.js diff --git a/api/notFound.js b/api/notFound.js new file mode 100644 index 0000000..84bdd0e --- /dev/null +++ b/api/notFound.js @@ -0,0 +1,5 @@ +const createError = require('http-errors') + +module.exports = async (ctx, next) => { + throw createError(404) +} diff --git a/index.js b/index.js index 58ae477..211330f 100644 --- a/index.js +++ b/index.js @@ -6,9 +6,10 @@ const { middlewareCompose } = require('./libs/helper') const functions = require('@google-cloud/functions-framework') const handlers = middlewareCompose([ - require('./cors'), + require('./api/cors'), require('./api/index'), require('./line/handler/index'), + require('./api/notFound'), ]) functions.http('main', async (req, res) => { diff --git a/line/handler/index.js b/line/handler/index.js index 42fd504..817f2d4 100644 --- a/line/handler/index.js +++ b/line/handler/index.js @@ -13,6 +13,7 @@ const lineEventHander = middlewareCompose([ module.exports = async (ctx, next) => { const { req, res } = ctx + if (req.method !== 'POST' || _.isNil(req.get('x-line-signature'))) return await next() try { // 處理 access token const channelAccessToken = req.path.substring(1)