How to use sirv - 10 common examples

To help you get started, we’ve selected a few sirv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github drejohnson / sapper-graphql-firebase / src / server.js View on Github external
import 'abort-controller/polyfill'
import 'isomorphic-unfetch'
import sirv from 'sirv'
import polka from 'polka'
import compression from 'compression'
import * as sapper from '@sapper/server'

const { PORT = 3000, NODE_ENV } = process.env
const dev = NODE_ENV === 'development'

const app = polka() // You can also use Express
  .use(
    compression({ threshold: 0 }),
    sirv('static', { dev: process.env.NODE_ENV === 'development' }),
    sapper.middleware(),
  )

export default app

if (dev) {
  app.listen(PORT, err => {
    if (err) console.log('error', err)
  })
}
github sw-yx / ssg / packages / ssg / ejectableFiles / server.js View on Github external
(req, res, next) => {
      if (fs.existsSync('static')) {
        // console.log(`serving 'static' folder...`)
        sirv('static', { dev })(req, res, next)
      } else {
        // console.log(`no 'static' folder found, not serving it..`)
        next()
      }
    },
    sapper.middleware(),
github sveltejs / sapper-template / src / server.js View on Github external
import sirv from 'sirv';
import polka from 'polka';
import compression from 'compression';
import * as sapper from '@sapper/server';

const { PORT, NODE_ENV } = process.env;
const dev = NODE_ENV === 'development';

polka() // You can also use Express
	.use(
		compression({ threshold: 0 }),
		sirv('static', { dev }),
		sapper.middleware()
	)
	.listen(PORT, err => {
		if (err) console.log('error', err);
	});
github sw-yx / ssg / packages / ssg / defaultSrcFiles / server.js View on Github external
(req, res, next) => {
      if (fs.existsSync('static')) {
        // console.log(`serving 'static' folder...`)
        sirv('static', { dev })(req, res, next)
      } else {
        // console.log(`no 'static' folder found, not serving it..`)
        next()
      }
    },
    sapper.middleware(),
github sveltecasts / 003-auth-ssr-firebase-svelte / src / server.js View on Github external
import sirv from 'sirv';
import express from 'express';
import compression from 'compression';
import * as sapper from '@sapper/server';
import bodyParser from 'body-parser'
import cookieParser from 'cookie-parser'
import admin from './firebase'
const { PORT, NODE_ENV } = process.env;
const dev = NODE_ENV === 'development';

express() // You can also use Express
	.use(

		compression({ threshold: 0 }),
		sirv('static', { dev }),
		cookieParser(),
		bodyParser.json(),
		(req, res, next) => {
			const sessionCookie = req.cookies["__session"] || '';
			// Verify the session cookie. In this case an additional check is added to detect
			// if the user's Firebase session was revoked, user deleted/disabled, etc.
			admin.auth().verifySessionCookie(
				sessionCookie, true /** checkRevoked */)
				.then((decodedClaims) => {
					//serveContentForUser('/profile', req, res, decodedClaims);
					console.log(decodedClaims)
					res.currentUser = { displayName: decodedClaims.name }
					next()
				})
				.catch(error => {
					// Session cookie is unavailable or invalid. Force user to login.
github sveltejs / sapper / test / apps / export / src / server.js View on Github external
import sirv from 'sirv';
import polka from 'polka';
import * as sapper from '@sapper/server';

import { start, dev } from '../../common.js';

const app = polka()
	.use(
		sirv('static', { dev }),
		sapper.middleware()
	);

start(app);
github lampewebdev / svelte-blog-stream / src / server.js View on Github external
try {
		db = await openDbAndCreateTable();
		const blogPosts = await markdownLoader();
		await insertBlogPosts({ db, blogPosts });
	} catch (error) {
		db.close();
	}
	const dbmiddleware = () => function (req, res, next) {
		req.db = db;
		next();
	};
	polka()
		.use(
			dbmiddleware(),
			compression({ threshold: 0 }),
			sirv("static", { dev }),
			sapper.middleware()
		)
		.listen(PORT, err => {
			if (err) console.log("error", err);
		});
})();
github timhall / svelte-apollo / example / app / server.js View on Github external
Book: {
    author(book) {
      return authors.find(author => author.id === book.author);
    }
  }
};

const server = new ApolloServer({ typeDefs, resolvers });

const app = express();
server.applyMiddleware({ app });

app
  .use(
    compression({ threshold: 0 }),
    sirv('assets'),
    sapper({
      routes,
      App,
      store: req => {
        const client = new ApolloClient({
          ssrMode: true,
          link: createHttpLink({
            uri: 'http://localhost:3000/graphql',
            credentials: 'same-origin',
            headers: {
              cookie: req.header('Cookie')
            }
          }),
          cache: new InMemoryCache()
        });
        const graphql = createProvider(client, { ssr: true });
github babichjacob / sapper-firebase-typescript-graphql-tailwindcss-actions-template / src / server.js View on Github external
createSapperAndApolloServer = async (dev_) => {
		const app = await createExpressServer();
		if (dev_) app.use(compression({threshold: 0}), sirv("static", {dev: true}));

		app.use(sapper.middleware());
		return app;
	};
github domingues / svelte-ssr-example / src / server.js View on Github external
return { page };
}

const HOST = process.env.NODE_HOST || 'localhost';
const PORT = process.env.NODE_PORT || 3000;
const PUBLIC_STATIC_PATH = 'STATIC_PATH';
const DEV = 'DEV_SERVER' === 'true';

const { clientImports, serverClientMap } = parseBundleTree('client-tree.json', PUBLIC_STATIC_PATH);

const server = polka();
if (DEV) {
    server.use(compression({ threshold: 0 }));
    let p = PUBLIC_STATIC_PATH.replace(/^(^\w+:|^)\/\/[\w.:]+/, '').replace(/[/]*$/, '');
    server.use(p, sirv(path.join(__dirname, 'client'), {
        setHeaders: res => {
            res.setHeader('Access-Control-Allow-Origin', '*');
        },
        maxAge: 31536000,
        immutable: true
    }));
}
const respond = (req, res) => {
    let code, html;
    try {
        const props = req.method === 'GET' ? (req.query.props ? req.query.props : '{}') : (req.body ? req.body : '{}');
        const result = buildPage(req.params['*'] ? req.params['*'] : 'index', props, clientImports, serverClientMap);
        if (result.error) {
            code = 500;
            html = `Error ${result.error}:<br><pre>${result.code}</pre>`;
        } else {

sirv

The optimized & lightweight middleware for serving requests to static assets

MIT
Latest version published 1 month ago

Package Health Score

83 / 100
Full package analysis

Popular sirv functions