Giter VIP home page Giter VIP logo

svelte-adapter-deno's Introduction

svelte-adapter-deno

Adapter for SvelteKit apps that generates a standalone Deno server.

Usage

Install with npm i -D svelte-adapter-deno, then add the adapter to your svelte.config.js:

// svelte.config.js
import adapter from 'svelte-adapter-deno';

export default {
  kit: {
    adapter: adapter()
  }
};

After building the server (npm run build), use the following command to start:

# with the default build directory
deno run --allow-env --allow-read --allow-net build/index.js

# with a custom build directory
deno run --allow-env --allow-read --allow-net path/to/build/index.js

You can use the deployctl GitHub Action to automatically deploy your app in Deno Deploy:

.github/workflows/ci.yml

name: ci

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  deploy:
    name: deploy
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read

    steps:
      - name: Clone repository
        uses: actions/checkout@v2

      - name: Install Node
        uses: actions/setup-node@v2
        with:
          node-version: 16

      - name: Cache pnpm modules
        uses: actions/cache@v2
        with:
          path: ~/.pnpm-store
          key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-

      - name: Install pnpm and node_modules
        uses: pnpm/action-setup@v2
        with:
          version: latest
          run_install: true

      - name: Build site
        run: pnpm build
        working-directory: '<root>' # if necessary, should contain {out}

      - name: Deploy to Deno Deploy
        uses: denoland/deployctl@v1
        with:
          project: <YOUR PROJECT NAME>
          entrypoint: '{out}/index.js' # same as `out` option in config
          root: '<root>' # if necessary

The server needs at least the following permissions to run:

  • allow-env - allow environment access, to support runtime configuration via runtime variables (can be further restricted to include just the necessary variables)
  • allow-read - allow file system read access (can be further restricted to include just the necessary directories)
  • allow-net - allow network access (can be further restricted to include just the necessary domains)

In the documentation deno run -A is used for simplicity rather than as a recommendation, use only the necessary permissions in general use.

Environment variables

PORT and HOST

By default, the server will accept connections on 0.0.0.0 using port 3000. These can be customised with the PORT and HOST environment variables:

HOST=127.0.0.1 PORT=4000 deno run --allow-env --allow-read --allow-net build/server.js

ADDRESS_HEADER and XFF_DEPTH

The RequestEvent object passed to hooks and endpoints includes an event.getClientAddress() function that returns the client's IP address. By default this is the connecting remoteAddress. If your server is behind one or more proxies (such as a load balancer), this value will contain the innermost proxy's IP address rather than the client's, so we need to specify an ADDRESS_HEADER to read the address from:

ADDRESS_HEADER=True-Client-IP node build

Headers can easily be spoofed. As with PROTOCOL_HEADER and HOST_HEADER, you should know what you're doing before setting these.

If the ADDRESS_HEADER is X-Forwarded-For, the header value will contain a comma-separated list of IP addresses. The XFF_DEPTH environment variable should specify how many trusted proxies sit in front of your server. E.g. if there are three trusted proxies, proxy 3 will forward the addresses of the original connection and the first two proxies:

<client address>, <proxy 1 address>, <proxy 2 address>

Some guides will tell you to read the left-most address, but this leaves you vulnerable to spoofing:

<spoofed address>, <client address>, <proxy 1 address>, <proxy 2 address>

We instead read from the right, accounting for the number of trusted proxies. In this case, we would use XFF_DEPTH=3.

If you need to read the left-most address instead (and don't care about spoofing) — for example, to offer a geolocation service, where it's more important for the IP address to be real than trusted, you can do so by inspecting the x-forwarded-for header within your app.

Options

The adapter can be configured with various options:

/// file: svelte.config.js
import adapter from '@sveltejs/adapter-node';

export default {
  kit: {
    adapter: adapter({
      // default options are shown
      out: 'build',
      precompress: false,
      envPrefix: '',
      deps: './deps.ts' // (relative to adapter-deno package)
    })
  }
};

out

The directory to build the server to. It defaults to build — i.e. deno run -A build/index.js would start the server locally after it has been created.

precompress

Enables precompressing using gzip and brotli for assets and prerendered pages. It defaults to false.

envPrefix

If you need to change the name of the environment variables used to configure the deployment (for example, to deconflict with environment variables you don't control), you can specify a prefix:

envPrefix: 'MY_CUSTOM_';
MY_CUSTOM_HOST=127.0.0.1 \
MY_CUSTOM_PORT=4000 \
MY_CUSTOM_ORIGIN=https://my.site \
deno run -A build/index.js

deps

The file re-exporting external runtime dependencies (deps.ts by convention in Deno). It defaults to the deps.ts file included in the package.

Custom server

The adapter creates two files in your build directory — index.js and handler.js. Running index.js — e.g. deno run -A build/index.js, if you use the default build directory — will start a server on the configured port.

Alternatively, you can import the handler.js file, which exports a handler suitable for use with Oak and set up your own server:

/// file: my-server.js
import { Application, Router } from 'https://deno.land/x/[email protected]/mod.ts';
import { handler } from './build/handler.js';

const app = new Application();

// add a route that lives separately from the SvelteKit app
const router = new Router();
router.get('/healthcheck', (ctx) => {
  ctx.response.body = 'ok';
});
app.use(router.routes());
app.use(router.allowedMethods());

// let SvelteKit handle everything else, including serving prerendered pages and static assets
app.use(handler);

app.addEventListener('listen', () => {
  console.log('listening on port 3000');
});
await app.listen({ port: 3000 });

License

MIT

svelte-adapter-deno's People

Contributors

cangit avatar heliumbrain avatar jpaquim avatar justjavac avatar thehadiahmadi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

svelte-adapter-deno's Issues

npm run build return "builder.getBuildDirectory"

I have an app in sveltekit and I used to build with node adapter. Now I want to chance to deno, and the adapter hays "builder.getBuildDirectory" when I try to compile.

Have any idea?

thanks

Error during build writeStatic

Hello,

I'm tried to build my apps with latest sveltekit and get this error :

> Using svelte-adapter-deno
error during build:
Error: writeStatic has been removed. Please ensure you are using the latest version of svelte-adapter-deno
    at Object.writeStatic (file:///home/rifkidhan/Rifki/web/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/dist/chunks/index3.js:211:10)
    at adapt (file:///home/rifkidhan/Rifki/web/node_modules/.pnpm/[email protected]/node_modules/svelte-adapter-deno/index.js:39:12)
    at adapt (file:///home/rifkidhan/Rifki/web/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/dist/chunks/index3.js:255:8)
    at Object.closeBundle (file:///home/rifkidhan/Rifki/web/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/dist/vite.js:2407:11)
    at async Promise.all (index 0)
    at async Object.close (file:///home/rifkidhan/Rifki/web/node_modules/.pnpm/[email protected]/node_modules/rollup/dist/es/shared/rollup.js:23662:13)
    at async Promise.all (index 0)
    at async build (file:///home/rifkidhan/Rifki/web/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-5cb728cb.js:43408:13)
    at async CAC.<anonymous> (file:///home/rifkidhan/Rifki/web/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/cli.js:747:9)
 

When i'm tried delete this line, build success.

builder.writeStatic(`${out}/static`);

Thanks.

What should I do if I already have a Deno app?

I'm from ASP.NET Core and am learning Deno, oak and looking at the newer breed of JS frameworks.

I've struggled immensely with Svelte because I can't understand how it fits into my mental model of a web app. I don't understand how my existing Deno app serves the Svelte content that, I think, Vite produces.

I'd expect there to be Svelte middleware, or maybe I render some outer HTML via Eta and put some Svelte JS entrypoint in that. I don't know.

I'm also not used to coding via a dev HTTP server that isn't the actual web server (and so doesn't have my middleware in effect).

I was told to research Svelte Adapters and here I am. This adapter appears to emit the whole Deno app? Is that right (I'm a noob)? So I can't integrate Svelte with an existing Deno app serving some other pages and static files?

Thanks for any advice :)

npm run build fails

Any idea how to fix this?

> Using svelte-adapter-deno
✘ [ERROR] Could not resolve "./deps.ts"

    .svelte-kit/deno/index.js:1:56:
      1 │ import { dirname, fromFileUrl, join, Application } from './deps.ts';
        ╵                                                         ~~~~~~~~~~~

✘ [ERROR] Could not resolve "better-sqlite3"

    .svelte-kit/output/server/entries/endpoints/api/players.js:2:7:
      2 │ import "better-sqlite3";
        ╵        ~~~~~~~~~~~~~~~~

  The "main" field here was ignored. Main fields must be configured explicitly when using the
  "neutral" platform.

    node_modules/better-sqlite3/package.json:11:2:
      11 │   "main": "lib/index.js",
         ╵   ~~~~~~

  You can mark the path "better-sqlite3" as external to exclude it from the bundle, which will
  remove this error.

✘ [ERROR] Could not resolve "better-sqlite3"

    .svelte-kit/output/server/chunks/db-2acc2369.js:1:21:
      1 │ import Database from "better-sqlite3";
        ╵                      ~~~~~~~~~~~~~~~~

  The "main" field here was ignored. Main fields must be configured explicitly when using the
  "neutral" platform.

    node_modules/better-sqlite3/package.json:11:2:
      11 │   "main": "lib/index.js",
         ╵   ~~~~~~

  You can mark the path "better-sqlite3" as external to exclude it from the bundle, which will
  remove this error.

✘ [ERROR] Could not resolve "better-sqlite3"

    .svelte-kit/output/server/entries/endpoints/players.js:2:7:
      2 │ import "better-sqlite3";
        ╵        ~~~~~~~~~~~~~~~~

  The "main" field here was ignored. Main fields must be configured explicitly when using the
  "neutral" platform.

    node_modules/better-sqlite3/package.json:11:2:
      11 │   "main": "lib/index.js",
         ╵   ~~~~~~

  You can mark the path "better-sqlite3" as external to exclude it from the bundle, which will
  remove this error.

✘ [ERROR] Could not resolve "better-sqlite3"

    .svelte-kit/output/server/entries/endpoints/index.js:2:7:
      2 │ import "better-sqlite3";
        ╵        ~~~~~~~~~~~~~~~~

  The "main" field here was ignored. Main fields must be configured explicitly when using the
  "neutral" platform.

    node_modules/better-sqlite3/package.json:11:2:
      11 │   "main": "lib/index.js",
         ╵   ~~~~~~

  You can mark the path "better-sqlite3" as external to exclude it from the bundle, which will
  remove this error.

✘ [ERROR] Could not resolve "better-sqlite3"

    .svelte-kit/output/server/entries/endpoints/games.js:2:7:
      2 │ import "better-sqlite3";
        ╵        ~~~~~~~~~~~~~~~~

  The "main" field here was ignored. Main fields must be configured explicitly when using the
  "neutral" platform.

    node_modules/better-sqlite3/package.json:11:2:
      11 │   "main": "lib/index.js",
         ╵   ~~~~~~

  You can mark the path "better-sqlite3" as external to exclude it from the bundle, which will
  remove this error.

> Build failed with 6 errors:
.svelte-kit/deno/index.js:1:56: ERROR: Could not resolve "./deps.ts"
.svelte-kit/output/server/chunks/db-2acc2369.js:1:21: ERROR: Could not resolve "better-sqlite3"
.svelte-kit/output/server/entries/endpoints/api/players.js:2:7: ERROR: Could not resolve "better-sqlite3"
.svelte-kit/output/server/entries/endpoints/games.js:2:7: ERROR: Could not resolve "better-sqlite3"
.svelte-kit/output/server/entries/endpoints/index.js:2:7: ERROR: Could not resolve "better-sqlite3"
...
.svelte-kit/deno/index.js:1:56: ERROR: Could not resolve "./deps.ts"
.svelte-kit/output/server/chunks/db-2acc2369.js:1:21: ERROR: Could not resolve "better-sqlite3"
.svelte-kit/output/server/entries/endpoints/api/players.js:2:7: ERROR: Could not resolve "better-sqlite3"
.svelte-kit/output/server/entries/endpoints/games.js:2:7: ERROR: Could not resolve "better-sqlite3"
.svelte-kit/output/server/entries/endpoints/index.js:2:7: ERROR: Could not resolve "better-sqlite3"
...
    at failureErrorWithLog (/home/..../app/node_modules/esbuild/lib/main.js:1603:15)
    at /home/..../app/node_modules/esbuild/lib/main.js:1249:28
    at runOnEndCallbacks (/home/..../app/node_modules/esbuild/lib/main.js:1162:65)
    at buildResponseToResult (/home/..../app/node_modules/esbuild/lib/main.js:1247:7)
    at /home/..../app/node_modules/esbuild/lib/main.js:1356:14
    at /home/..../app/node_modules/esbuild/lib/main.js:666:9
    at handleIncomingPacket (/home/..../app/node_modules/esbuild/lib/main.js:763:9)
    at Socket.readFromStdout (/home/..../app/node_modules/esbuild/lib/main.js:632:7)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)

Dynamic import is not enabled in this context.

When using version "0.9.0", an error will be reported when deploying to deno. I use deployctl to deploy.

TypeError: Dynamic import is not enabled in this context.
    at async respond_with_error (file:///src/server/index.js:2293:28)
    at async resolve (file:///src/server/index.js:3611:16)
    at async respond (file:///src/server/index.js:3490:22)
    at async ssr (file:///src/handler.js:34:19)
    at async handler (file:///src/handler.js:80:11)
    at async dispatch (https://deno.land/x/[email protected]/middleware.ts:41:7)
    at async Application.#handleRequest (https://deno.land/x/[email protected]/application.ts:436:9) {
  code: "ERR_MODULE_NOT_FOUND"
}

When I change the version back to "0.8.2" it deploys successfully. I don't know what causes this.

Deno deploy support?

Howdy!

I ran through quickly setting up a new sveltekit project, added the deno adapter and wanted to deploy it straight away into deno deploy but it came up with the following error:

TypeError: Deno.lstatSync is not a function
    at existsSync (https://deno.land/[email protected]/fs/exists.ts:19:14)
    at createServer (file:///src/dist/index.js:2229:31)
    at file:///src/dist/index.js:2266:16

Is supporting deno deploy a direction that ya'll want to go in?

edit: Here's a link to the project if you'd like to take a look

Mark it as external to exclude it from the bundle

Hi, I'm getting this error message when I'm trying to build. How do I mark a package as external? Thanks!

> Build failed with 1 error:
.svelte-kit/output/server/app.js:20:29: error: Could not resolve "@supabase/supabase-js" 
(mark it as external to exclude it from the bundle)

Assets throw a 404 when running behind a reverse proxy.

I'm using this adapter to run a site, however, the static content like images and CSS styles get behind and directly throw a 404.

This is my systemd unit service:

[Unit]
Description = Sveltekit Deno

[Service]
Type = simple
User = www-data
Group = www-data
LimitNOFILE = 4096
Restart = always
RestartSec = 5s
ExecStart = /usr/bin/deno run --allow-env --allow-read --allow-net /var/www/html/site.com/build/index.js

[Install] 
WantedBy = multi-user.target

The NGINX configuration i'm using is the following (the important proxy part):

	location / {
		proxy_set_header Connection '';
        	proxy_http_version 1.1;
        	proxy_read_timeout 180s;

        	proxy_set_header Host $host;
        	proxy_set_header X-Real-IP $remote_addr;
        	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        	proxy_set_header X-Forwarded-Proto $scheme;
    		proxy_set_header X-NginX-Proxy true;

        	proxy_pass http://localhost:3000;
	}

However this results in an error when going to the main site:

image

No loader is configured....

I am trying to switch from Netlify to Deno Deploy and I am running into this issue:

✘ [ERROR] No loader is configured for ".node" files: node_modules/three-em-0-3-16/three_em_node.win32-x64-msvc.node

which seems to be related to some deno/node incompatibility. Three_em fortunately do have a deno version of their library, but I don't know how to substitute it. I tried adding an import map

{
  "imports": {
    "three_em": "https://deno.land/x/[email protected]/index.js"
  }
}

to no avail.

Example deno run command not working

The command deno run --allow-env --allow-read --allow-net path/to/build/server.js in the readme.md is currently not working.

You will get this error:

TS2497 [ERROR]: This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.
export { default as ms } from "https://cdn.skypack.dev/[email protected]?dts";

This issue cmorten/opine#146 is describing the problem.

You need to have a tsconfig.json file with the following content:

{
	"compilerOptions": {
		"allowSyntheticDefaultImports": true
	}
}

And add the --config ./tsconfig.json to the command.

deno run --allow-env --allow-read --allow-net --config ./tsconfig.json path/to/build/server.js.

Error related to getIterator

Hello,

I am currently facing an issue with the Svelte adapter for deno.

When running SvelteKit's build process, I don't get any error.
However, whn running :

deno run  --allow-env --allow-read --allow-net --config tsconfig.deno.json build/index.js

I get this error :

Unsupported compiler options in "file:///[pathToMyProject]/tsconfig.deno.json".
  The following options were ignored:
    allowSyntheticDefaultImports
Check file:///[pathToMyProject]/build/index.js
error: TS2339 [ERROR]: Property 'getIterator' does not exist on type 'ReadableStream<R>'.
  return res.readable.getIterator();
                      ~~~~~~~~~~~
    at https://deno.land/[email protected]/async/pool.ts:45:23

TS2578 [ERROR]: Unused '@ts-expect-error' directive.
      // @ts-expect-error
      ~~~~~~~~~~~~~~~~~~~
    at https://deno.land/[email protected]/node/events.ts:100:7

TS2578 [ERROR]: Unused '@ts-expect-error' directive.
        // @ts-expect-error
        ~~~~~~~~~~~~~~~~~~~
    at https://deno.land/[email protected]/node/events.ts:105:9

TS2578 [ERROR]: Unused '@ts-expect-error' directive.
      // @ts-expect-error
      ~~~~~~~~~~~~~~~~~~~
    at https://deno.land/[email protected]/node/events.ts:116:7

TS2578 [ERROR]: Unused '@ts-expect-error' directive.
      // @ts-expect-error
      ~~~~~~~~~~~~~~~~~~~
    at https://deno.land/[email protected]/node/events.ts:200:7

TS2578 [ERROR]: Unused '@ts-expect-error' directive.
    // @ts-expect-error
    ~~~~~~~~~~~~~~~~~~~
    at https://deno.land/[email protected]/node/events.ts:225:5

TS2578 [ERROR]: Unused '@ts-expect-error' directive.
        // @ts-expect-error
        ~~~~~~~~~~~~~~~~~~~
    at https://deno.land/[email protected]/node/events.ts:391:9

TS2578 [ERROR]: Unused '@ts-expect-error' directive.
      // @ts-expect-error
      ~~~~~~~~~~~~~~~~~~~
    at https://deno.land/[email protected]/node/events.ts:424:7

I used the tsconfig.deno.json provided with the package.
The options I set in the svelte.config.js are the build path, the deps (I set it to "./deps.ts" as in the README, I also tried moving the example in the package to the build folder) and enabled procompression.

I can provide further information if necessary.

Thanks ;)

`Broken pipe (os error 32)` if cancellig request

How to reproduce

  1. Start a server
  2. Navigate to localhost:3000
  3. Cancel page load (hitting the "X" button in place of reload, or any other disconnection)
  4. Server crashes
> deno run -A ./build/server.js
Listening on port 3000
# (Cancelling a load)
error: Uncaught (in promise) BrokenPipe: Broken pipe (os error 32)
          numBytesWritten = await this.writer.write(data);
                            ^
    at deno:core/01_core.js:106:46
    at unwrapOpResult (deno:core/01_core.js:126:13)
    at async write (deno:extensions/net/01_net.js:26:12)
    at async BufWriter.write (https://deno.land/[email protected]/io/bufio.ts:501:29)
    at async writeResponse (https://deno.land/[email protected]/http/_io.ts:275:15)
    at async ServerRequest.respond (https://deno.land/[email protected]/http/server.ts:87:7)
    at async Response.end (https://deno.land/x/[email protected]/src/response.ts:256:7)

It seems to be the the same issue described here: denoland/deno_std#659 (comment), where the error will happen, but is not correctly caught, thus the crash.

Probably some part of server.js needs to be wrapped in a trycatch to prevent it crashing the entire server (the traceback couldn't be less useful), but other than that I don't know what could be done (without going upstream to opine, and that seems to be already done: cmorten/opine#102 (comment))

Adapter static but with Deno support?

Feel free to close if this is considered off-topic.

Can you offer any guidance on how to setup SvelteKit in such a way as to run builds with Deno but get the output produced by adapter-static? Instead of a Deno server, I'd like to end up with static HTML files but built with TypeScript end to end.

Use 'fs': Dynamic require of "fs" is not supported

After building, running my Sveltekit project with deno run --allow-env --allow-read --allow-net build/index.js fails with

error: Uncaught Error: Dynamic require of "fs" is not supported
  throw new Error('Dynamic require of "' + x2 + '" is not supported');

I use a single readdir command in my Sveltekit backend

import { readdir } from 'fs/promises';
...
const files = await readdir(...);

To my deps.ts file I have added

export { readdir } from "https://deno.land/[email protected]/node/fs/promises.ts";
// export { fs } from "node:fs";
// export { readdir } from "node:fs/promises";

export { exists } from 'https://deno.land/[email protected]/fs/mod.ts';
export { dirname, extname, fromFileUrl, join } from "https://deno.land/[email protected]/path/mod.ts";
export { Application } from 'https://deno.land/x/[email protected]/mod.ts';

The readdir import does not remove the error and the built-in fs imports do not work

X [ERROR] Could not resolve "node:fs"

    .svelte-kit/deno/deps.ts:3:19:
      3 │ export { fs } from "node:fs";
        ╵                    ~~~~~~~~~

  The package "node:fs" wasn't found on the file system but is built into node. Are you trying to
  bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

Are 'fs' and other built-in node modules expected to work?

Unable to use Deno inside a components' script tags

<script>
	const res = await fetch('https://example-29544e.webflow.io');
</script>

produces the following error

Cannot use keyword 'await' outside an async functionsvelte(parse-error)
'await' expressions are only allowed within async functions and at the top levels of modules.js(1308)

I started my development server via npm run dev but it looks like it's still running node rather than Deno. Can I get some help?

Add an option to disable listening [feature-request]

I think Deno is looking much more promising than Node, so I decided to try building Fullstack applications with Deno and SvelteKit. But what I get from using svelte-adapter-deno is kind of not what I wanted.

When running npm run build with this adapter what I end up with is a single file which creates the server and starts listening. But I think that's kind of limiting the user experience. When building a fullstack app you want to create API routes and do some server-side logic in Deno app. But doing it with current file structure that is being ouputted by the adapter is not that easy

I think it would be better if the adapter had an option to disable listening (server.listen(...) in the outputted file build/index.js) so that developers could choose what they want from this adapter:
a. Only one single file to just run it with deno run -A build/index.js as is (listen: true)
b. The file that exports the handler and they can add some backend logic to it and use it however they want basically (listen: false)

In my opinion it might look like this:

// svelte.config.js
import adapter from 'svelte-adapter-deno';

export default {
  kit: {
    adapter: adapter({
      out: 'build',
      listen: false,
      deps: './deps.ts'
    })
  }
};

And then you could do something like this:

import { Application, Router } from "https://deno.land/x/[email protected]/mod.ts";
import { handler } from '../build/index.js'

const data = {
  id: 1,
  name: 'John Silver'
}

const router = new Router()
router.get('/api/data', (ctx) => {
  ctx.response.headers.set('Content-Type', 'application/json')
  ctx.response.body = JSON.stringify(data)
})

const app = new Application()

app.use(router.routes())
app.use(router.allowedMethods())
app.use(handler)

app.addEventListener("listen", () => {
  console.log('Listening on http://localhost:8000');
})

await app.listen({ port: 8000 })

Cannot read property 'minor' of undefined

Hello!

Just tried using the adapter - both in my excisting svelte-kit project and in a fresh one using npm init svelte@next. Getting the same error during npm run build in both:

> Using svelte-adapter-deno
> Cannot read property 'minor' of undefined
TypeError: Cannot read property 'minor' of undefined
    at adapt (file:///Users/nilskanevad/code/svelte-kit-playground/node_modules/svelte-adapter-deno/index.js:26:14)
    at adapt (file:///Users/nilskanevad/code/svelte-kit-playground/node_modules/@sveltejs/kit/dist/chunks/index6.js:338:8)
    at file:///Users/nilskanevad/code/svelte-kit-playground/node_modules/@sveltejs/kit/dist/cli.js:894:11

My svelte-config.js looks like this:

import preprocess from 'svelte-preprocess';
import adapter from 'svelte-adapter-deno'

/** @type {import('@sveltejs/kit').Config} */
const config = {
  // Consult https://github.com/sveltejs/svelte-preprocess
  // for more information about preprocessors
  preprocess: preprocess(),

  kit: {
    adapter: adapter({
      // default options are shown
      out: 'build',
      deps: './deps.ts' // (relative to adapter-deno package)
    })
    }
};

export default config;

SvelteKit v1.0.0-next.125
Vite v2.4.2

Allow for a rollup config hook

Allow for a rollup config hook so we can change the rollup config.

I needed this feature because graphql.js seems to export esm with process.env.NODE_ENV checks. So simply adding

adapter: adapter({
  rollupHook: (options) => {
      options.plugins.push(replace({
          'process.env.NODE_ENV': JSON.stringify('production'),
      }))
  },
}),

was enough to solve my issue

Default deps.ts file is not included in the NPM package

Hi again,

It seems like your NPM package does not include the default deps.ts that is in this repo. Following the instructions in the README fails on deno run since there is no deps.ts file to read from.

If I copy the deps.ts from the repo and add it to my project root before npm run build it gets picked up and copied over to the build folder.

Is this intended? If so, you might want to update the README to state that you need to create deps.tsyourself. If not, add it to the files section in package.json so it get's included in the NPM package.

Dynamic import is not enabled in this context (deno-deploy)

Hi, I tried using the adapter and push my code to deno deploy but I'm getting this error when loading the published site :

TypeError: Dynamic import is not enabled in this context.
    at async Promise.all (index 0)
    at async respond (file:///src/build/server/index.js:3420:23)
    at async ssr (file:///src/build/handler.js:34:19)
    at async handler (file:///src/build/handler.js:80:11)
    at async dispatch (https://deno.land/x/[email protected]/middleware.ts:18:13)
    at async allowedMethods (https://deno.land/x/[email protected]/router.ts:350:13)
    at async dispatch (https://deno.land/x/[email protected]/middleware.ts:18:13)
    at async dispatch (https://deno.land/x/[email protected]/middleware.ts:18:13)
    at async Application.#handleRequest (https://deno.land/x/[email protected]/application.ts:198:17)

I was wondering if you ever encountered this problem ?

[Bug] TypeError: Cannot read properties of null (reading 'trailing_slash')

Hi there,

Currently, I find a replace solution for ReactJS/Vuejs. And i choose Svelte

I use adapter withSvelteKit demo app no any change in code
But I get a bug with router

TypeError: Cannot read properties of null (reading 'trailing_slash')
    at respond (file:///project-workspace/svelkit/build/app.js:1285:41)
    at render (file:///project-workspace/svelkit/build/app.js:1720:10)
    at file:///project-workspace/svelkit/build/server.js:73:27
    at async Layer.handle [as handle_request] (https://deno.land/x/[email protected]/src/router/layer.ts:76:5)

Workflow:

  1. Add adapter to svelte.config.js
  2. Build sveltekit with npm run build
  3. Open http://localhost:3000
  4. Click to pages Home, About, Todo workfine
  5. But in /todo page, with a refresh i get a error with trailing_slash

Any reply for fix it?

SvelteKit update breaks deno-adapter

`[WARNING] Import "dirname" will always be undefined because the file ".svelte-kit/deno/deps.ts" has no exports [import-is-undefined]

.svelte-kit/deno/index.js:1:9:
  1 │ import { dirname, fromFileUrl, join, exists, Application } from './deps.ts';
    ╵          ~~~~~~~

▲ [WARNING] Import "fromFileUrl" will always be undefined because the file ".svelte-kit/deno/deps.ts" has no exports [import-is-undefined]

.svelte-kit/deno/index.js:1:18:
  1 │ import { dirname, fromFileUrl, join, exists, Application } from './deps.ts';

.svelte-kit/deno/index.js:1:37:
  1 │ import { dirname, fromFileUrl, join, exists, Application } from './deps.ts';
    ╵                                      ~~~~~~

▲ [WARNING] Import "Application" will always be undefined because the file ".svelte-kit/deno/deps.ts" has no exports [import-is-undefined]

.svelte-kit/deno/index.js:1:45:
  1 │ import { dirname, fromFileUrl, join, exists, Application } from './deps.ts';
    ╵                                              ~~~~~~~~~~~

PS C:\Users\Administrator\Desktop\x> pnpm run deno

x@ deno C:\Users\Administrator\Desktop\x
deno run --allow-env --allow-read --allow-net xbuild_deno/index.js

error: Uncaught TypeError: (void 0) is not a function
var __dirname = (void 0)((void 0)(import.meta.url));
^
at file:///C:/Users/Administrator/Desktop/x/xbuild_deno/index.js:3540:34
 ELIFECYCLE  Command failed with exit code 1.
`

update body

See sveltejs/kit#2215

I didn't look closely, but you might need to update this line:

export async function getRawBody(req) {

This is the last breaking change on the 1.0 milestone affecting SvelteKit adapters, so while no promises, hopefully there won't be any more changes required after this

Thanks for providing this adapter!

Looking for clarity about the use-case of this project

Context: I would like to build a website with svelte kit that makes calls to HTTP API written in Deno and some DB to store some state about the users. Probably key-value store. I would like to explore the most efficient setup (resources, money). I am familiar with the basics of Svelte but not with Deno.

How would the development experience looks like, how would the deployment experience looks like and how would a production setup looks like? Are we talking about a single codebase with server folder and a client folder that are deployed to the host and also a Caddy (or reverse proxy) in front of them? and the way to access them is my-app.com and api.my-app.com?

Are there simpler solutions? and is this project even relevant to my usecase?

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.