Skip to content

Commit

Permalink
Merge pull request #69 from serlo/build/esbuild-commonjs
Browse files Browse the repository at this point in the history
build: esbuild commonjs
  • Loading branch information
hejtful authored Sep 27, 2024
2 parents a2fd8bb + 7a3104c commit a55b07a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:20.17.0 as build
WORKDIR /usr/src/app

COPY . .
RUN yarn install --immutable

RUN yarn build

FROM node:20.17.0 as production

WORKDIR /usr/src/app

COPY --from=build /usr/src/app/dist dist

EXPOSE 3000

ENTRYPOINT ["node", "dist/backend/index.cjs"]
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ RUN yarn build

EXPOSE 3000

ENTRYPOINT ["yarn", "start:dev"]
ENTRYPOINT ["yarn", "start"]
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "module",
"scripts": {
"build": "npm-run-all --parallel \"build:*\"",
"build:backend": "esbuild src/backend/index.ts --bundle --platform=node --format=esm --packages=external --outfile=dist/backend/index.js",
"build:backend": "esbuild ./src/backend/index.ts --bundle --platform=node --outfile=dist/backend/index.cjs",
"build:frontend": "vite build",
"dev": "docker compose up --watch --build",
"format": "npm-run-all --sequential --continue-on-error \"format:*\"",
Expand All @@ -23,7 +23,7 @@
"push-image:dev": "yarn push-image dev",
"push-image:latest": "yarn push-image latest",
"start:dev": "tsx --watch src/backend/index.ts",
"start": "node dist/backend/index.js"
"start": "node dist/backend/index.cjs"
},
"dependencies": {
"@serlo/editor": "0.14.0",
Expand Down
10 changes: 3 additions & 7 deletions src/backend/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { Provider as ltijs } from 'ltijs'
import 'dotenv/config'
import path, { dirname } from 'path'
import { fileURLToPath } from 'url'
import path from 'path'
import jwt from 'jsonwebtoken'
import { Pool, createPool } from 'mysql2/promise'
import { Database } from './database'
import { v4 as uuidv4 } from 'uuid'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const ltijsKey = readEnvVariable('LTIJS_KEY')
const mongodbConnectionUri = readEnvVariable('MONGODB_CONNECTION_URI')
const ltiPlatform = {
Expand Down Expand Up @@ -72,7 +68,7 @@ ltijs.setup(
loginUrl: '/lti/login',
keysetUrl: '/lti/keys',
dynRegRoute: '/lti/register',
staticPath: path.join(__dirname, './../../dist'), // Path to static files
staticPath: path.join(__dirname, './../../dist/frontend'), // Path to static files
cookies: {
secure: process.env['ENVIRONMENT'] === 'local' ? false : true, // Set secure to true if the testing platform is in a different domain and https is being used
sameSite: process.env['ENVIRONMENT'] === 'local' ? '' : 'None', // Set sameSite to 'None' if the testing platform is in a different domain and https is being used
Expand All @@ -88,7 +84,7 @@ ltijs.app.use((_, res, next) => {

// Opens Serlo editor
ltijs.app.get('/app', async (_, res) => {
return res.sendFile(path.join(__dirname, '../../dist/index.html'))
return res.sendFile(path.join(__dirname, '../../dist/frontend/index.html'))
})

// Endpoint to get content
Expand Down

0 comments on commit a55b07a

Please sign in to comment.