diff --git a/cdk/lib/sovellus-stack.ts b/cdk/lib/sovellus-stack.ts index 2530f6a1..6e75a359 100644 --- a/cdk/lib/sovellus-stack.ts +++ b/cdk/lib/sovellus-stack.ts @@ -332,9 +332,49 @@ export class SovellusStack extends cdk.Stack { autoDeleteObjects: true }); + const swaggerKeyPrefix = 'swagger'; const staticS3Deployment = new s3deploy.BucketDeployment(this, 'DeployWebsite', { sources: [s3deploy.Source.asset('../static')], destinationBucket: staticBucket, + destinationKeyPrefix: swaggerKeyPrefix, + }); + + /** + * Raportointikäyttöliittymä + */ + const lambdaAdapterLayer = lambda.LayerVersion.fromLayerVersionArn( + this, + 'LambdaAdapterLayerX86', + `arn:aws:lambda:${this.region}:753240598075:layer:LambdaAdapterLayerX86:19` + ); + + const raportointiKayttoliittymaFunction = new lambda.Function(this, 'NextCdkFunction', { + functionName: `${props.environmentName}-viestinvalityspalvelu-raportointikayttoliittyma`, + runtime: lambda.Runtime.NODEJS_18_X, + handler: 'run.sh', + memorySize: 1024, + timeout: Duration.seconds(60), + code: lambda.Code.fromAsset(path.join( + __dirname, + '../../viestinvalitys-raportointi/.next/', 'standalone') + ), + architecture: lambda.Architecture.X86_64, + environment: { + 'AWS_LAMBDA_EXEC_WRAPPER': '/opt/bootstrap', + 'RUST_LOG': 'info', + 'PORT': '8080', + }, + layers: [lambdaAdapterLayer], + }); + + const raportointiKayttoliittymaFunctionUrl = raportointiKayttoliittymaFunction.addFunctionUrl({ + authType: FunctionUrlAuthType.NONE, + }); + + const nextJsS3Deployment = new s3deploy.BucketDeployment(this, 'NextJsStaticDeployment', { + sources: [s3deploy.Source.asset('../viestinvalitys-raportointi/.next/static')], + destinationBucket: staticBucket, + destinationKeyPrefix: 'static/_next/static' }); const cloudfrontOAI = new cloudfront.OriginAccessIdentity( @@ -422,16 +462,44 @@ export class SovellusStack extends cdk.Stack { eventType: cloudfront.FunctionEventType.VIEWER_REQUEST, }], }, - '/raportointi/*': { + '/raportointi/login': { origin: new cloudfront_origins.HttpOrigin(Fn.select(2, Fn.split('/', raportointiFunctionUrl.url)), {}), cachePolicy: noCachePolicy, viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL, originRequestPolicy, }, + '/raportointi/login/*': { + origin: new cloudfront_origins.HttpOrigin(Fn.select(2, Fn.split('/', raportointiFunctionUrl.url)), {}), + cachePolicy: noCachePolicy, + viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, + allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL, + originRequestPolicy, + }, + '/raportointi': { + origin: new cloudfront_origins.HttpOrigin(Fn.select(2, Fn.split('/', raportointiKayttoliittymaFunctionUrl.url)), {}), + cachePolicy: noCachePolicy, + viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, + allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL, + originRequestPolicy, + }, + '/raportointi/v1/*': { + origin: new cloudfront_origins.HttpOrigin(Fn.select(2, Fn.split('/', raportointiFunctionUrl.url)), {}), + cachePolicy: noCachePolicy, + viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, + allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL, + originRequestPolicy, + }, + '/raportointi/*': { + origin: new cloudfront_origins.HttpOrigin(Fn.select(2, Fn.split('/', raportointiKayttoliittymaFunctionUrl.url)), {}), + cachePolicy: noCachePolicy, + viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, + allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL, + originRequestPolicy, + }, '/static/*': { origin: new cloudfront_origins.S3Origin(staticBucket, { - originAccessIdentity: cloudfrontOAI + originAccessIdentity: cloudfrontOAI, }), cachePolicy: noCachePolicy, viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, diff --git a/lambdat/raportointi/src/main/scala/fi/oph/viestinvalitys/raportointi/configuration/SecurityConfiguration.scala b/lambdat/raportointi/src/main/scala/fi/oph/viestinvalitys/raportointi/configuration/SecurityConfiguration.scala index defecb56..54516655 100644 --- a/lambdat/raportointi/src/main/scala/fi/oph/viestinvalitys/raportointi/configuration/SecurityConfiguration.scala +++ b/lambdat/raportointi/src/main/scala/fi/oph/viestinvalitys/raportointi/configuration/SecurityConfiguration.scala @@ -40,7 +40,7 @@ class SecurityConfiguration { @Bean def serviceProperties(@Value("${cas-service.service}") service: String, @Value("${cas-service.sendRenew}") sendRenew: Boolean): ServiceProperties = { val serviceProperties = new ServiceProperties() - serviceProperties.setService(service + RaportointiAPIConstants.RAPORTOINTI_API_PREFIX + "/j_spring_cas_security_check") + serviceProperties.setService(service + RaportointiAPIConstants.RAPORTOINTI_API_PREFIX + "/login/j_spring_cas_security_check") serviceProperties.setSendRenew(sendRenew) serviceProperties.setAuthenticateAllArtifacts(true) serviceProperties @@ -74,7 +74,7 @@ class SecurityConfiguration { def casAuthenticationFilter(authenticationManager: AuthenticationManager, serviceProperties: ServiceProperties): CasAuthenticationFilter = { val casAuthenticationFilter = new OpintopolkuCasAuthenticationFilter(serviceProperties) casAuthenticationFilter.setAuthenticationManager(authenticationManager) - casAuthenticationFilter.setFilterProcessesUrl(RaportointiAPIConstants.RAPORTOINTI_API_PREFIX + "/j_spring_cas_security_check") + casAuthenticationFilter.setFilterProcessesUrl(RaportointiAPIConstants.RAPORTOINTI_API_PREFIX + "/login/j_spring_cas_security_check") casAuthenticationFilter } diff --git a/lambdat/raportointi/src/main/scala/fi/oph/viestinvalitys/raportointi/resource/LoginResource.scala b/lambdat/raportointi/src/main/scala/fi/oph/viestinvalitys/raportointi/resource/LoginResource.scala index 4bbd441b..735756a4 100644 --- a/lambdat/raportointi/src/main/scala/fi/oph/viestinvalitys/raportointi/resource/LoginResource.scala +++ b/lambdat/raportointi/src/main/scala/fi/oph/viestinvalitys/raportointi/resource/LoginResource.scala @@ -18,6 +18,13 @@ class LoginResource { @GetMapping(path = Array(RaportointiAPIConstants.LOGIN_PATH)) def redirect(response: HttpServletResponse): Unit = { - response.sendRedirect("localhost:3000") + response.sendRedirect("/raportointi") } + + // CloudFront ohjaa tämä polun nodelle, joten tätä uudelleenohjausta käytetään vain lokaalisti + @GetMapping(path = Array("raportointi")) + def redirectToNodeLocally(response: HttpServletResponse): Unit = { + response.sendRedirect("http://localhost:3000") + } + } \ No newline at end of file diff --git a/lambdat/vastaanotto/src/main/scala/fi/oph/viestinvalitys/vastaanotto/configuration/SecurityConfiguration.scala b/lambdat/vastaanotto/src/main/scala/fi/oph/viestinvalitys/vastaanotto/configuration/SecurityConfiguration.scala index 52bbf934..179858e0 100644 --- a/lambdat/vastaanotto/src/main/scala/fi/oph/viestinvalitys/vastaanotto/configuration/SecurityConfiguration.scala +++ b/lambdat/vastaanotto/src/main/scala/fi/oph/viestinvalitys/vastaanotto/configuration/SecurityConfiguration.scala @@ -43,7 +43,7 @@ class SecurityConfiguration { @Bean def serviceProperties(@Value("${cas-service.service}") service: String, @Value("${cas-service.sendRenew}") sendRenew: Boolean): ServiceProperties = { val serviceProperties = new ServiceProperties() - serviceProperties.setService(service + LahetysAPIConstants.LAHETYS_API_PREFIX + "/j_spring_cas_security_check") + serviceProperties.setService(service + LahetysAPIConstants.LAHETYS_API_PREFIX + "/login/j_spring_cas_security_check") serviceProperties.setSendRenew(sendRenew) serviceProperties.setAuthenticateAllArtifacts(true) serviceProperties @@ -77,7 +77,7 @@ class SecurityConfiguration { def casAuthenticationFilter(authenticationManager: AuthenticationManager, serviceProperties: ServiceProperties): CasAuthenticationFilter = { val casAuthenticationFilter = new OpintopolkuCasAuthenticationFilter(serviceProperties) casAuthenticationFilter.setAuthenticationManager(authenticationManager) - casAuthenticationFilter.setFilterProcessesUrl(LahetysAPIConstants.LAHETYS_API_PREFIX + "/j_spring_cas_security_check") + casAuthenticationFilter.setFilterProcessesUrl(LahetysAPIConstants.LAHETYS_API_PREFIX + "/login/j_spring_cas_security_check") casAuthenticationFilter } diff --git a/static/static/swagger-ui/favicon-16x16.png b/static/swagger-ui/favicon-16x16.png similarity index 100% rename from static/static/swagger-ui/favicon-16x16.png rename to static/swagger-ui/favicon-16x16.png diff --git a/static/static/swagger-ui/favicon-32x32.png b/static/swagger-ui/favicon-32x32.png similarity index 100% rename from static/static/swagger-ui/favicon-32x32.png rename to static/swagger-ui/favicon-32x32.png diff --git a/static/static/swagger-ui/index.css b/static/swagger-ui/index.css similarity index 100% rename from static/static/swagger-ui/index.css rename to static/swagger-ui/index.css diff --git a/static/static/swagger-ui/index.html b/static/swagger-ui/index.html similarity index 100% rename from static/static/swagger-ui/index.html rename to static/swagger-ui/index.html diff --git a/static/static/swagger-ui/oauth2-redirect.html b/static/swagger-ui/oauth2-redirect.html similarity index 100% rename from static/static/swagger-ui/oauth2-redirect.html rename to static/swagger-ui/oauth2-redirect.html diff --git a/static/static/swagger-ui/swagger-initializer.js b/static/swagger-ui/swagger-initializer.js similarity index 100% rename from static/static/swagger-ui/swagger-initializer.js rename to static/swagger-ui/swagger-initializer.js diff --git a/static/static/swagger-ui/swagger-ui-bundle.js b/static/swagger-ui/swagger-ui-bundle.js similarity index 100% rename from static/static/swagger-ui/swagger-ui-bundle.js rename to static/swagger-ui/swagger-ui-bundle.js diff --git a/static/static/swagger-ui/swagger-ui-bundle.js.map b/static/swagger-ui/swagger-ui-bundle.js.map similarity index 100% rename from static/static/swagger-ui/swagger-ui-bundle.js.map rename to static/swagger-ui/swagger-ui-bundle.js.map diff --git a/static/static/swagger-ui/swagger-ui-es-bundle-core.js b/static/swagger-ui/swagger-ui-es-bundle-core.js similarity index 100% rename from static/static/swagger-ui/swagger-ui-es-bundle-core.js rename to static/swagger-ui/swagger-ui-es-bundle-core.js diff --git a/static/static/swagger-ui/swagger-ui-es-bundle-core.js.map b/static/swagger-ui/swagger-ui-es-bundle-core.js.map similarity index 100% rename from static/static/swagger-ui/swagger-ui-es-bundle-core.js.map rename to static/swagger-ui/swagger-ui-es-bundle-core.js.map diff --git a/static/static/swagger-ui/swagger-ui-es-bundle.js b/static/swagger-ui/swagger-ui-es-bundle.js similarity index 100% rename from static/static/swagger-ui/swagger-ui-es-bundle.js rename to static/swagger-ui/swagger-ui-es-bundle.js diff --git a/static/static/swagger-ui/swagger-ui-es-bundle.js.map b/static/swagger-ui/swagger-ui-es-bundle.js.map similarity index 100% rename from static/static/swagger-ui/swagger-ui-es-bundle.js.map rename to static/swagger-ui/swagger-ui-es-bundle.js.map diff --git a/static/static/swagger-ui/swagger-ui-standalone-preset.js b/static/swagger-ui/swagger-ui-standalone-preset.js similarity index 100% rename from static/static/swagger-ui/swagger-ui-standalone-preset.js rename to static/swagger-ui/swagger-ui-standalone-preset.js diff --git a/static/static/swagger-ui/swagger-ui-standalone-preset.js.map b/static/swagger-ui/swagger-ui-standalone-preset.js.map similarity index 100% rename from static/static/swagger-ui/swagger-ui-standalone-preset.js.map rename to static/swagger-ui/swagger-ui-standalone-preset.js.map diff --git a/static/static/swagger-ui/swagger-ui.css b/static/swagger-ui/swagger-ui.css similarity index 100% rename from static/static/swagger-ui/swagger-ui.css rename to static/swagger-ui/swagger-ui.css diff --git a/static/static/swagger-ui/swagger-ui.css.map b/static/swagger-ui/swagger-ui.css.map similarity index 100% rename from static/static/swagger-ui/swagger-ui.css.map rename to static/swagger-ui/swagger-ui.css.map diff --git a/static/static/swagger-ui/swagger-ui.js b/static/swagger-ui/swagger-ui.js similarity index 100% rename from static/static/swagger-ui/swagger-ui.js rename to static/swagger-ui/swagger-ui.js diff --git a/static/static/swagger-ui/swagger-ui.js.map b/static/swagger-ui/swagger-ui.js.map similarity index 100% rename from static/static/swagger-ui/swagger-ui.js.map rename to static/swagger-ui/swagger-ui.js.map diff --git a/viestinvalitys-raportointi/.env.template b/viestinvalitys-raportointi/.env.template index 43072a14..fa9540a9 100644 --- a/viestinvalitys-raportointi/.env.template +++ b/viestinvalitys-raportointi/.env.template @@ -3,4 +3,4 @@ VIESTINTAPALVELU_URL=http://localhost:8080/ LOGIN_URL=http://localhost:8080/login # matchattava viestintäpalvelun asettaman raportointisession cookien nimeen -COOKIE_NAME=JSESSIONID \ No newline at end of file +COOKIE_NAME=JSESSIONID \ No newline at end of file diff --git a/viestinvalitys-raportointi/next.config.js b/viestinvalitys-raportointi/next.config.js index 767719fc..debf2809 100644 --- a/viestinvalitys-raportointi/next.config.js +++ b/viestinvalitys-raportointi/next.config.js @@ -1,4 +1,10 @@ /** @type {import('next').NextConfig} */ const nextConfig = {} -module.exports = nextConfig +//module.exports = nextConfig + +module.exports = { + output: 'standalone', + basePath: '/raportointi', + assetPrefix: '/static', +} diff --git a/viestinvalitys-raportointi/package.json b/viestinvalitys-raportointi/package.json index 333c9712..0c75deb8 100644 --- a/viestinvalitys-raportointi/package.json +++ b/viestinvalitys-raportointi/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "NODE_TLS_REJECT_UNAUTHORIZED=0 next dev", - "build": "next build", + "build": "next build; cp run.sh .next/standalone", "start": "next start", "lint": "next lint", "test": "vitest" diff --git a/viestinvalitys-raportointi/run.sh b/viestinvalitys-raportointi/run.sh new file mode 100755 index 00000000..8355875d --- /dev/null +++ b/viestinvalitys-raportointi/run.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +export PORT=8080 +export VIESTINTAPALVELU_URL=https://viestinvalitys.hahtuvaopintopolku.fi +export LOGIN_URL=https://viestinvalitys.hahtuvaopintopolku.fi/raportointi/login +export COOKIE_NAME=JSESSIONID + +node server.js