Skip to content
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

kit/packages/adapter-node/index.d.ts contains removed properties - entryPoint and esbuild #3175

Closed
nstuyvesant opened this issue Jan 1, 2022 · 4 comments
Labels

Comments

@nstuyvesant
Copy link
Contributor

nstuyvesant commented Jan 1, 2022

Describe the bug

Had a custom server working in prod using adapter-node 1.0.0-next.52. After updating to 1.0.0-next.58, I changed the

import { assetsMiddleware, prerenderedMiddleware, kitMiddleware } from '../build/middlewares.js'
...
.use(assetsMiddleware, prerenderedMiddleware, kitMiddleware)

to

import { handler } from '../build/handler.js'
...
  .use(handler)

Builds seem to completely ignore my entryPoint in svelte.config.js. Full code is below.

Reproduction

svelte.config.js

import adapter from '@sveltejs/adapter-node'
import preprocess from 'svelte-preprocess'
import helmet from 'helmet'

const production = process.env.NODE_ENV === 'production'
const { PORT = 3000 } = process.env

/** @type {import('@sveltejs/kit').Config} */
const config = {
	preprocess: preprocess(),
	kit: {
		adapter: adapter({
			entryPoint: './src/server.mjs',
			precompress: true
		}),
		target: '#svelte',
		vite: {
			optimizeDeps: {
				include: ['@carbon/charts'],
				exclude: ['@carbon/telemetry']
			},
			server: {
				fs: {
					// Allow serving files from one level up to the project root
					allow: [
						'..',
						'/api/file/'
					]
				}
			},
			serviceWorker: {
				files: (filepath) => !/\.DS_Store/.test(filepath)
			},
			ssr: {
				noExternal: [production && "@carbon/charts"].filter(Boolean)
			}
		}
	}
}

export default config

/src/server.mjs

// Set file using adapter-node's entryPoint property in svelte.config.js
import polka from 'polka'
import helmet from 'helmet'
import { handler } from '../build/handler.js'
// was import { assetsMiddleware, prerenderedMiddleware, kitMiddleware } from '../build/middlewares.js'

const { PORT = 3000, DOMAIN } = process.env

const isHttpPerHeroku = (req) =>
	req.headers['x-forwarded-proto'] &&
	req.headers['x-forwarded-proto'] !== 'https'

polka()
  // On Heroku (only), redirect http to https
  .use((req, res, next) => {
    if (isHttpPerHeroku(req)) {
      let url = `${DOMAIN}${req.url}`
      let str = `Redirecting to ${url}`
      res.writeHead(302, {
        Location: url,
        'Content-Type': 'text/plain',
        'Content-Length': str.length
      })
      res.end(str)
    } else next()
  })

  // Apply all but two helmet protections
  .use(helmet({
    contentSecurityPolicy: false, // default overrides below
    referrerPolicy: false // breaks "Sign in with Gooogle"
  }))

  // Load the SvelteKit build
  .use(handler) // was .use(assetsMiddleware, prerenderedMiddleware, kitMiddleware)


  // Listen on the appropriate port
  .listen(PORT)

Logs

No response

System Info

System:
    OS: macOS 12.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 3.91 GB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.1 - /opt/homebrew/Cellar/node@16/16.13.1/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.1.2 - /opt/homebrew/Cellar/node@16/16.13.1/bin/npm
  Browsers:
    Chrome: 96.0.4664.110
    Safari: 15.2
  npmPackages:
    @sveltejs/adapter-node: next => 1.0.0-next.58 
    @sveltejs/kit: next => 1.0.0-next.212 
    svelte: ^3.44.3 => 3.44.3

Severity

blocking an upgrade

Additional Information

Cannot deploy the app because it lacks a content security policy now.

@bluwy
Copy link
Member

bluwy commented Jan 2, 2022

@nstuyvesant Can you provide a GitHub repro or a StackBlitz link to setup the reproduction given? Looks like there's a lot of configuration needed for someone to take a look at the bug.

@jasonlyu123
Copy link
Member

The esbuild option and the entryPoint option in the adapter node have been removed. Though the type doesn't it is removed from the readme. There's also no bundling option now, see #3176.

I don't know what is the recommended way to migrate. But now you'll have to copy your custom server file and copy the dependencies or install dependencies on the production server.

@nstuyvesant nstuyvesant changed the title Upgrade adapter-node from 1.0.0-next.52 to 1.0.0-next.58 and custom server not working Upgraded adapter-node from 1.0.0-next.52 to 1.0.0-next.58 entryPoint removed from adapter options Jan 2, 2022
@nstuyvesant
Copy link
Contributor Author

@jasonlyu123 - thanks. Looks like #2931 in 1.0.0-next.57 released 4 days ago will force me to refactor my configuration.

An easy approach is to add to the build script to copy my server.mjs file to the build directory and make the appropriate adjustments to my start script and Procfile (for Heroku).

As you pointed out, it looks like the only bugs here are in kit/packages/adapter-node/index.d.ts. These three lines should be deleted so it's clear the esbuild and entryPoint properties were removed:
https://github.com/sveltejs/kit/blob/master/packages/adapter-node/index.d.ts#L2
https://github.com/sveltejs/kit/blob/master/packages/adapter-node/index.d.ts#L5
https://github.com/sveltejs/kit/blob/master/packages/adapter-node/index.d.ts#L13

@nstuyvesant nstuyvesant changed the title Upgraded adapter-node from 1.0.0-next.52 to 1.0.0-next.58 entryPoint removed from adapter options kit/packages/adapter-node/index.d.ts contains removed properties - entryPoint and esbuild Jan 2, 2022
@nstuyvesant
Copy link
Contributor Author

Closed via #3181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants