I have a few js files used in my serverless functions (they are like libraries) and I have reached maximum serverless functions count. I’m looking for a simple way that will let me keep them unaccessible from users but accessible to functions for require(“foo.js”)
Hey @nxrix
can you explain a little more about your setup:
- Libraries or frameworks being used
- Any current errors you are seeing
- Are you in a monorepo setup or a single monolithic repository?
More than happy to dive in, I think a little more context will help me steer the conversation to find a solution faster.
I’m not using any frameworks, I have a small repo with no actual errors
the files I said about look like this and I have used them in other places
//--ai.js--//
const tokens = (i) => {
let t = 0;
for (const m of i) {
t += m.content.split(" ").length;
}
return t;
};
const limit_tokens = (i,x) => {
let t = 0;
let l = [];
for (let n=i.length-1;n>=0;n--) {
const m = i[n];
const c = m.content.split(" ").length;
if (t+c<=x) {
l.unshift(m);
t += c;
} else {
l.unshift({ ...m , content: m.content.split(" ").slice(-x+t).join(" ") });
break;
}
}
return l;
};
const groq_gen = async (messages,model="gemma2-9b-it",temperature=1,top_p=1,max_completion_tokens=1024) => {
const res = await fetch("https://api.groq.com/openai/v1/chat/completions",{
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer ******"
},
body: JSON.stringify({
messages,
model,
temperature,
top_p,
max_completion_tokens,
stop: null
})
});
return await res.json();
};
module.exports = {
tokens,
limit_tokens,
groq_gen
}
Ah ok, no problem!
Most common reason is probably putting everything in an /api
. If you go to your project and select your deployment, there is a Sources
tab that you should see to look at the input and the output of your project.
I created a test project just now that is this input:
This is the output
Notice the lib/test.js
is not marked as a lambda. I think that is what you are looking for.
Let me know if I’m off, happy to keep digging in
Thank you! That’s what I’m looking for but as I said there is 1 more problem that I need to fix,
The lib folder and it’s files are accessible within the deployment url but I don’t want it to be accessible
Can you elaborate more?
In my example, the lib folder I’m unable to access directly from the client/deployment (ex. browser), but the /api/test can use that lib/test and process a request.
There may also be some project config that could help you here?
Very interested, let me know!
Can’t find why but mine doesn’t work
I used
{
"routes": [
{
"src": "/lib/(.*)",
"dest": "/404.html"
}
]
}
and I think it’s fixed for now
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.