Skip to content

Commit

Permalink
move server code into preview directory
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Sep 13, 2021
1 parent 2f09909 commit 7486720
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
File renamed without changes.
37 changes: 34 additions & 3 deletions packages/kit/src/core/preview/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import fs from 'fs';
import { pathToFileURL } from 'url';
import http from 'http';
import https from 'https';
import { join, resolve } from 'path';
import sirv from 'sirv';
import { pathToFileURL } from 'url';
import { getRawBody } from '../node/index.js';
import { join, resolve } from 'path';
import { get_server } from '../server/index.js';
import { __fetch_polyfill } from '../../install-fetch.js';
import { SVELTE_KIT, SVELTE_KIT_ASSETS } from '../constants.js';

Expand Down Expand Up @@ -128,3 +129,33 @@ export async function preview({

return Promise.resolve(server);
}

/**
* @param {boolean} use_https
* @param {import('vite').UserConfig} user_config
* @param {(req: http.IncomingMessage, res: http.ServerResponse) => void} handler
* @returns {Promise<import('net').Server>}
*/
async function get_server(use_https, user_config, handler) {
/** @type {https.ServerOptions} */
const https_options = {};

if (use_https) {
const secure_opts = user_config.server
? /** @type {import('tls').SecureContextOptions} */ (user_config.server.https)
: {};

if (secure_opts.key && secure_opts.cert) {
https_options.key = secure_opts.key.toString();
https_options.cert = secure_opts.cert.toString();
} else {
https_options.key = https_options.cert = (await import('./cert')).createCertificate();
}
}

return Promise.resolve(
use_https
? https.createServer(/** @type {https.ServerOptions} */ (https_options), handler)
: http.createServer(handler)
);
}
32 changes: 0 additions & 32 deletions packages/kit/src/core/server/index.js

This file was deleted.

0 comments on commit 7486720

Please sign in to comment.