From 3e67ea585f5d3ca5976013e2deb38daadb5eb6aa Mon Sep 17 00:00:00 2001 From: Vanja Oljaca Date: Mon, 3 Jul 2023 21:32:41 -1000 Subject: [PATCH] fixed, but also ffs still ffs logging --- main/{index.test.ts.disable => index.test.ts} | 15 +++++++++++++-- main/index.ts | 14 +++++++------- package.json | 3 ++- wallaby.js | 2 +- 4 files changed, 23 insertions(+), 11 deletions(-) rename main/{index.test.ts.disable => index.test.ts} (89%) diff --git a/main/index.test.ts.disable b/main/index.test.ts similarity index 89% rename from main/index.test.ts.disable rename to main/index.test.ts index 2ddfd08..8350a56 100644 --- a/main/index.test.ts.disable +++ b/main/index.test.ts @@ -23,7 +23,7 @@ describe('azure function handler', () => { 'legal.txt', 'openapi.yaml' ] - it.only('static', async () => { + it('static', async () => { for (const p of paths) { let res = await invokeMain( { route: p }, @@ -31,6 +31,17 @@ describe('azure function handler', () => { assert.ok(res); } }) + const badpaths = [ + '../ai-plugin.json', + ] + it('static', async () => { + for (const p of badpaths) { + let res = await invokeMain( + { route: p }, + { body: true }, { id: 7 }) + assert.ok(res.body.startsWith('Invalid')); + } + }) }) @@ -54,7 +65,7 @@ describe('azure function handler', () => { }) describe('azure function handler', () => { - it('can chat', async () => { + xit('can chat', async () => { let res = await invokeMain( { route: 'api/main/chat' }, { diff --git a/main/index.ts b/main/index.ts index 8c2f5ae..f2fd110 100644 --- a/main/index.ts +++ b/main/index.ts @@ -199,11 +199,10 @@ async function serveStatic(context: Context, req: HttpRequest) { // Check if the file path is still within the base path if (!filePath.startsWith(basePath)) { //? - context.res = { + return { status: 400, - body: "Invalid path" + body: "Invalid path: " + filePath + ' ' + basePath, }; - return; } const fileContent = fs.readFileSync(filePath, 'utf8'); @@ -222,15 +221,16 @@ const pattern = new UrlPattern('api/main/:api(/*)'); export const run: AzureFunction = async function (context: Context, req: HttpRequest) { - context.log('run', req) - return { run: true } + context.log('context run', req) + try { - console.log('run', req) + console.log('console run', req) const route = pattern.match(req.params.route); //? if (route) { context.log('route', route) + console.log('cons route', route) const api = route.api; const query = req.query as unknown as any; // IMainQuery; const body = req.body as unknown as IMainBody; @@ -254,7 +254,7 @@ export const run: AzureFunction = async function (context: Context, req: HttpReq } catch (error) { context.log('error', error) return { - error + body: error } } diff --git a/package.json b/package.json index c35409a..5f9ed1a 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "", "scripts": { "copy-content": "cp -R content/ dist/content/", - "build": "tsc && yarn copy-content", + "copy-static": "cp -R main/static/ dist/main/static/", + "build": "tsc && yarn copy-content && yarn copy-static", "watch": "tsc -w", "prestart": "npm run build", "start": "func start", diff --git a/wallaby.js b/wallaby.js index 9f677c5..5ac1281 100644 --- a/wallaby.js +++ b/wallaby.js @@ -10,7 +10,7 @@ module.exports = function (wallaby) { compilers: { '**/*.ts?(x)': wallaby.compilers.typeScript({ - outDir: './dist', + outDir: './.wallaby', // other TypeScript compiler options }) },