The serverless framework creates web servers that can run anywhere.
The serverless framework creates web servers that can run anywhere.
npx create-aircode-app@latest my-aircode-app && cd my-aircode-app
npm i && npm start
The default project directory structure is very simple.
βββfunctions # put your function api here.
βΒ βββ hello.js # http://localhost:3000/hello
βββpublic # put your static resources here.
βΒ βββ favicon.ico # http://localhost:3000/public/favicon.ico
βββ package.json
You can easily build your function api in ./functions
directory.
*.js
or *.cjs
// myfun.js
const aircode = require('aircode');
module.exports = async function(params, context) {
console.log('Received params:', params);
return {
message: 'Hi, AirCode.'
};
}
*.mjs
import aircode from 'aircode';
export default async function (params, context) {
console.log('Received params:', params);
return {
message: 'Hi, AirCode.',
};
};
*.ts
import aircode from 'aircode';
export default async function (params: any, context: any) {
console.log('Received params:', params);
return {
message: 'Hi, AirCode.',
};
};
Simply visit your built functions with http://localhost:3000/<your_func_name>
.
And visit your static resources with http://localhost:3000/public/<your_static_file>
.
There are a few options that you can pass through process.env.
process.env.AC_FAAS_ROOT = process.env.AC_FAAS_ROOT || 'functions';
process.env.AC_PUBLIC_DIR = process.env.AC_PUBLIC_DIR || 'public';
process.env.AC_PORT = process.env.AC_PORT || 3000;