Coder Social home page Coder Social logo

How to serve an Angular build about ltijs HOT 2 CLOSED

cvmcosta avatar cvmcosta commented on August 18, 2024
How to serve an Angular build

from ltijs.

Comments (2)

Cvmcosta avatar Cvmcosta commented on August 18, 2024

In order to serve static files (like your js files generated by angular), just like express you need to declare a static file path, in Ltijs you can do this by using the staticPath parameter in the constructor options object, example:

const lti = new LTI('EXAMPLEKEY', 
            { url: 'mongodb://localhost/database' }, 
            { appUrl: '/', staticPath: path.join(__dirname, 'public') })

further information: Serving static files in Express

from ltijs.

ahelord avatar ahelord commented on August 18, 2024

@Cvmcosta thank you very much.

const express = require('express')
// Require Provider
const LTI = require('ltijs').Provider
// Loading environment variables
const APP_FOLDER = 'public/dist/app/';

//require('dotenv').config()

// Creating a provider instance
const lti = new LTI('LTI_KEY',
  // Setting up database configurations
  { url: 'mongodb://localhost/test' },
  { appUrl: '/', loginUrl: '/login', logger: false,
    staticPath:APP_FOLDER})


  let setup = async () => {
    // Deploy and open connection to the database
    await lti.deploy()

    // Register platform
    const plat = await lti.registerPlatform({
      url: 'http://localhost:8081',
      name: 'Local Moodle 2',
      clientId: 'rbJKqLxYKEZRnGt',
      authenticationEndpoint: 'http://localhost:8081' + '/mod/lti/auth.php',
      accesstokenEndpoint: 'http://localhost:8081' + '/mod/lti/token.php',
      authConfig: { method: 'JWK_SET', key: 'http://localhost:8081' + '/mod/lti/certs.php' }
    })
    lti.onConnect((connection, request, response) => {
      // Call redirect function
      lti.redirect(response, '/main?locals='+response.locals.context.custom.apiKey)
    })

    // Set main endpoint route
    lti.app.get('/main', (req, res) => {
      // Id token
      console.log(res.locals)
      //res.send('It\'s alive!')
      console.log(__dirname)
      res.status(200).sendFile(`/`, {root: APP_FOLDER});

    })
}

  setup()

from ltijs.

Related Issues (20)

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.