Skip to content

Commit

Permalink
fixed, but also ffs still ffs logging
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjaoljaca committed Jul 4, 2023
1 parent e3ed244 commit 3e67ea5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
15 changes: 13 additions & 2 deletions main/index.test.ts.disable → main/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,25 @@ 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 },
{ body: true }, { id: 7 })
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'));
}
})
})


Expand All @@ -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' },
{
Expand Down
14 changes: 7 additions & 7 deletions main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand All @@ -254,7 +254,7 @@ export const run: AzureFunction = async function (context: Context, req: HttpReq
} catch (error) {
context.log('error', error)
return {
error
body: error
}
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion wallaby.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function (wallaby) {

compilers: {
'**/*.ts?(x)': wallaby.compilers.typeScript({
outDir: './dist',
outDir: './.wallaby',
// other TypeScript compiler options
})
},
Expand Down

0 comments on commit 3e67ea5

Please sign in to comment.