How to use the @foal/core.createApp function in @foal/core

To help you get started, we’ve selected a few @foal/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FoalTS / foal / packages / acceptance-tests / src / auth.typeorm.spec.ts View on Github external
class AppController {
      subControllers = [
        MyController,
        AuthController
      ];
    }

    await createConnection({
      database: 'e2e_db.sqlite',
      dropSchema: true,
      entities: [ User, Permission, Group ],
      synchronize: true,
      type: 'sqlite',
    });

    const app = createApp(AppController);

    /* Create a user */

    await createConnection({
      database: 'e2e_db.sqlite',
      dropSchema: true,
      entities: [ User, Permission, Group ],
      name: 'create-connection',
      synchronize: true,
      type: 'sqlite',
    });

    const user = new User();
    user.email = 'john@foalts.org';
    user.password = await hashPassword('password');
    await getRepository(User, 'create-connection').save(user);
github FoalTS / foal / packages / acceptance-tests / src / examples / validation-and-sanitization.spec.ts View on Github external
text: string;

      }

      class SocialPostController {

        @Post()
        @ValidateBodyFromClass(SocialPost, { /* options if relevant */ })
        createSocialPost() {
          // ...
          return new HttpResponseCreated();
        }

      }

      const app = createApp(SocialPostController);

      return request(app)
        .post('/')
        .send({ text: 'foo' })
        .expect(400)
        .expect([
          {
            children: [],
            constraints: { length: 'title must be longer than or equal to 10 characters' },
            property: 'title',
            target: { text: 'foo' },
          },
          {
            children: [],
            constraints: { contains: 'text must contain a hello string' },
            property: 'text',
github FoalTS / foal / samples / tutorials / nuxt.js / backend / src / index.ts View on Github external
async function main() {
  // Init Nuxt.js
  const nuxt = new Nuxt(config);

  // Build only in dev mode
  if (config.dev) {
    const builder = new Builder(nuxt);
    await builder.build();
  } else {
    await nuxt.ready();
  }

  await createConnection();

  const app = createApp(AppController, {
    postMiddlewares: [
      nuxt.render
    ]
  });

  const httpServer = http.createServer(app);
  const port = Config.get('port', 3001);
  httpServer.listen(port, () => {
    console.log(`Listening on port ${port}...`);
  });
}
github FoalTS / foal / packages / typeorm / e2e / rest.spec.ts View on Github external
class AuthController extends LoginController {
    strategies = [
      strategy('login', Authenticator, {})
    ];
  }

  class AppController {
    subControllers = [
      controller('/users', UserController),
      controller('/orgs', OrgController),
      controller('', AuthController),
    ];
  }

  const app = createApp(AppController);

  /* Create orgs, perms, groups and users */

  await createConnection({
    database: 'e2e_db.sqlite',
    dropSchema: true,
    entities: [ User, Permission, Group, Org ],
    name: 'create-connection',
    synchronize: true,
    type: 'sqlite',
  });

  const adminPerm = new Permission();
  adminPerm.name = 'Admin permission';
  adminPerm.codeName = 'admin-perm';
github FoalTS / foal / packages / acceptance-tests / src / authentication / session-token.cookie.spec.ts View on Github external
before(async () => {
    process.env.SETTINGS_SESSION_SECRET = 'session-secret';
    await createConnection({
      database: 'e2e_db.sqlite',
      dropSchema: true,
      entities: [ User ],
      synchronize: true,
      type: 'sqlite',
    });

    app = createApp(AppController);
  });
github FoalTS / foal / packages / acceptance-tests / src / authorization / groups-and-permissions.spec.ts View on Github external
group.codeName = 'administrators';
    group.permissions = [ perm ];
    await getRepository(Group).save(group);

    user1.userPermissions = [ perm ];
    user2.groups = [ group ];

    await getRepository(User).save([ user1, user2 ]);

    const session1 = await createService(TypeORMStore).createAndSaveSessionFromUser(user1);
    tokenUser1 = session1.getToken();

    const session2 = await createService(TypeORMStore).createAndSaveSessionFromUser(user2);
    tokenUser2 = session2.getToken();

    app = createApp(AppController);
  });
github FoalTS / foal / packages / acceptance-tests / src / mongoose-db.redis-store.spec.ts View on Github external
await new Promise((resolve, reject) => {
      redisClient.flushdb((err, success) => {
        if (err) {
          return reject(err);
        }
        resolve(success);
      });
    });

    const user = new UserModel();
    user.email = 'john@foalts.org';
    user.password = await hashPassword('password');
    user.isAdmin = false;
    await user.save();

    app = createApp(AppController);
  });
github FoalTS / foal / packages / acceptance-tests / src / mongoose-db.redis-store.spec.ts View on Github external
await new Promise((resolve, reject) => {
      redisClient.flushdb((err, success) => {
        if (err) {
          return reject(err);
        }
        resolve(success);
      });
    });

    const user = new UserModel();
    user.email = 'john@foalts.org';
    user.password = await hashPassword('password');
    user.isAdmin = false;
    await user.save();

    app = createApp(AppController);
  });
github FoalTS / foal / packages / social / src / github-provider.service.spec.ts View on Github external
it('should send a request with the access token and return the response body.', async () => {
      const userInfo = { email: 'john@foalts.org' };

      class AppController {
        @Get('/users/me')
        token(ctx: Context) {
          const { authorization } = ctx.request.headers;
          strictEqual(authorization, 'token an_access_token');
          return new HttpResponseOK(userInfo);
        }
      }

      server = createApp(AppController).listen(3000);

      const tokens: SocialTokens = {
        access_token: 'an_access_token',
        token_type: 'token_type'
      };

      const actual = await provider.getUserInfoFromTokens(tokens);
      deepStrictEqual(actual, userInfo);
    });
github FoalTS / foal / packages / examples / src / index.ts View on Github external
async function main() {
  await createConnection(require('../ormconfig.json'));

  const app = createApp(AppController);

  const httpServer = http.createServer(app);
  const port = Config.get('port', 3001);
  httpServer.listen(port, () => {
    console.log(`Listening on port ${port}...`);
  });
}