Skip to content
/ koa-svelte Public template

A simple template with Koa as backend and Svelte as frontend

Notifications You must be signed in to change notification settings

templates-world/koa-svelte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-svelte

koa-svelte is a template using Koa as backend and Svelte as frontend.

Getting started

Using a degit tool, you can install this template as:

npx degit Olyno/koa-svelte my-app

What contain this template

What could be added

  • Typescript support
    1. Install typescript dependecies: npm i -D typescript @types/koa @types/koa-static @types/koa-send ts-node
    2. Remove unused babel dependencies: npm uninstall -D @babel/core @babel/node @babel/preset-env
    3. Change the server/index.js file to server/index.ts and make it compatible with typescript:
    - import koa from 'koa';
    - import send from 'koa-send';
    - import serve from 'koa-static';
    + import * as koa from 'koa';
    + import * as send from 'koa-send';
    + import * as serve from 'koa-static';
    
    const PORT = 3000;
    
    const app = new koa();
    
    // Serve static assets
    app.use(serve('public'));
    
    // Serve index.html file
    app.use(async (ctx, next) => {
        await send(ctx, 'index.html', { root: 'public' });
        return next();
    })
    
    app.listen(PORT, () => console.log('> Server listening at http://localhost:' + PORT))
    1. Replace babel-node to ts-node inside the start script in your package.json file
    2. Remove unused .babelrc file
  • Security
    1. Install security dependencies: npm i koa-helmet koa-protect @koa/cors
    2. Add them into the server/index.js file:
    import koa from 'koa';
    import send from 'koa-send';
    import serve from 'koa-static';
    + import protect from 'koa-protect';
    + import helmet from 'koa-helmet';
    + import cors from '@koa/cors';
    
    const PORT = 3000;
    
    const app = new koa();
    
    + app.use(helmet());
    + app.use(cors());
    + app.use(protect.koa.sqlInjection({ body: true, loggerFunction: console.error }))
    + app.use(protect.koa.xss({ body: true, loggerFunction: console.error }))  
    
    // Serve static assets
    app.use(serve('public'));
    
    // Serve index.html file
    app.use(async (ctx, next) => {
        await send(ctx, 'index.html', { root: 'public' });
        return next();
    })
    
    app.listen(PORT, () => console.log('> Server listening at http://localhost:' + PORT))

About

A simple template with Koa as backend and Svelte as frontend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published