GithubHelp home page GithubHelp logo

aircodelabs / hydrogen Goto Github PK

View Code? Open in Web Editor NEW
132.0 9.0 5.0 88 KB

The serverless framework creates web servers that can run anywhere.

Home Page: https://aircode.io

License: MIT License

JavaScript 93.32% CSS 2.20% TypeScript 0.91% HTML 3.57%
faas javascript-framework nodejs serverless typescript

hydrogen's Introduction

Hydrogen

未标题-3

The serverless framework creates web servers that can run anywhere.

Features

  • 🐇 Rapid development with Hot Module Replacement (HMR) 🔥
  • 📦 Supports CommonJS (.js .cjs), ES modules (.mjs), and TypeScript (.ts) functions out of the box.
  • 🧸 Requires almost zero configurations.
  • 🗄️ Comes with a built-in, ready-to-use text database and file API.
  • 📁 Follows intuitive directory structure conventions.
  • 🤏 Written in Pure JavaScript with a sleek and minimalist design.
  • ⚡️ Optimized for runtime performance, regardless of development or production environments.
  • 🧊 Compatible and capable of running your app seamlessly on the AirCode platform.

Getting Started

  1. Create an aircode app
npx create-aircode-app@latest my-aircode-app && cd my-aircode-app
  1. Install dependencies and run
npm i && npm start

Directory Structure

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

Build Cloud Functions

You can easily build your function api in ./functions directory.

  1. With *.js or *.cjs
// myfun.js
const aircode = require('aircode');

module.exports = async function(params, context) {
  console.log('Received params:', params);
  return {
    message: 'Hi, AirCode.'
  };
}
  1. Or with *.mjs
import aircode from 'aircode';

export default async function (params, context) {
  console.log('Received params:', params);
  return {
    message: 'Hi, AirCode.',
  };
};
  1. Or with *.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>.

Documentation

Configurations

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;

Integration

Integration Hydrogen with AirCode online

hydrogen's People

Contributors

akira-cn avatar angusfu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hydrogen's Issues

关于数据库相关的问题

这个项目是必须依赖aircode云平台吗还是它是一个类似airecode云平台的开源?

数据库这块按照airecode文档执行的话

import aircode from 'aircode';

export default async function (params, context) {
  const dbs = aircode.db.table('persons');
  // Use `save` to add a new record
  const result = await dbs.save({
    name: 'Micheal',
    age: 28,
  });
  // const result = await dbs.where({ name: 'Micheal' }).find();

  return {
    result
  };
};

以上在hydroge中运行是访问api是没有任何信息的,数据是能正常在本地插入(如下图)
image
image

Questions about file downloads

  • windows10
  • Hydrogen:latest

Through aircode's upload API, files can be uploaded, but there will be problems with downloading, prompting no such file.
image
The results are as follows

import aircode from 'aircode';

export default async function (params, content) {
    // Get the file from multipart/form-data params, `myFile` is the key
    const { _id } = params;

    // You can do some permission checks before uploading
    // ...
    
    // Upload the file to AirCode
    const res = await aircode.files.download({
        // Replace the _id value with your file's
        _id
    });
    // return the URL of file
    return {
        res,
    };
}

image

2023-10-19 Additional information

I still think there is something wrong with using the airecode api for file upload and download in Hydrogen.

If you do not change the data when uploading and saving, only modify the download method as follows
https://github.com/AirCodeLabs/Hydrogen/blob/34d9a016cd7461d4f12ec053399846ad4b925437/src/runtime/file-service.js#L103C7-L103C76

filepath = path.resolve(process.env.AC_FAAS_ROOT, filepath.slice(1));

filepath = process.env.AC_FAAS_ROOT + filepath.slice(2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.