Skip to content

fix: template path, ts in serverless.ts, readme #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Netlify Build plugin Angular Serverless – Run Angular Universal seamlessly on Netlify](netlify-plugin-angular.png)
![Netlify Build plugin Angular Universal – Run Angular Universal seamlessly on Netlify](netlify-plugin-angular.png)

# Angular Universal Plugin

Expand Down Expand Up @@ -31,7 +31,7 @@ Create a `netlify.toml` in the root of your project. Your file should include th
```toml
[build]
command = "ng build --configuration production && ng run {projectName}:serverless:production"
publish = "dist/browser"
publish = "dist/{projectName}/browser"

[[plugins]]
package = "@netlify/plugin-angular-universal"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "src/index.js",
"files": [
"src/**/*.js",
"src/**/*.json",
"manifest.yml"
],
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path')

const TEMPLATES_DIR = path.join(__dirname, 'templates')

module.exports = {
TEMPLATES_DIR,
}
4 changes: 2 additions & 2 deletions src/helpers/addAngularServerlessFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const path = require('path')

const { copySync, writeFileSync } = require('fs-extra')

const { TEMPLATES_DIR } = require('../config')

const { getServerlessTs } = require('./getDynamicTemplates')

const addAngularServerlessFiles = ({ projectName, siteRoot }) => {
const TEMPLATES_DIR = path.join('src', 'templates')

// Write file with injected project name
writeFileSync(
path.join(siteRoot, 'serverless.ts'),
Expand Down
10 changes: 7 additions & 3 deletions src/helpers/getDynamicTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const getAngularBuilder = ({ functionServerPath }) => javascript`
`

const getServerlessTs = ({ projectName, siteRoot }) => javascript`
// @ts no-check
/// <reference types="zone.js" />
import 'zone.js/dist/zone-node'

Expand All @@ -45,8 +46,11 @@ const getServerlessTs = ({ projectName, siteRoot }) => javascript`

import { CommonEngine, RenderOptions } from '@nguniversal/common/engine';
import { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens';
// @ts-ignore
import MockExpressRequest from 'mock-express-request';
// @ts-ignore
import MockExpressResponse from 'mock-express-response';
// @ts-ignore
import qs from 'qs';

import { AppServerModule } from './src/main.server'
Expand All @@ -73,14 +77,14 @@ const getServerlessTs = ({ projectName, siteRoot }) => javascript`
}

// backwards compat for old CLI releases
function getRawQuery(event): string {
function getRawQuery(event: any): string {
if (event.rawQuery) {
return event.rawQuery;
}

return qs.stringify(event.multiValueQueryStringParameters, { arrayFormat: 'repeat' })
}
function getRawUrl(event): string {
function getRawUrl(event: any): string {
if (event.rawUrl) {
return event.rawUrl;
}
Expand All @@ -92,7 +96,7 @@ const getServerlessTs = ({ projectName, siteRoot }) => javascript`
return (event.headers['x-forwarded-proto'] || 'http') + "://" + event.headers.host + event.path + query;
}

export async function render(event, context): Promise<RenderResponse> {
export async function render(event: any, context: any): Promise<RenderResponse> {
const { method, path, headers, multiValueHeaders } = event;
let query = getRawQuery(event);
if (!!query) {
Expand Down