Skip to content

Instantly share code, notes, and snippets.

@cyclecycle
Last active June 4, 2019 13:43
Show Gist options
  • Save cyclecycle/19c98ca8b757fce3908c952ccb2c1e5c to your computer and use it in GitHub Desktop.
Save cyclecycle/19c98ca8b757fce3908c952ccb2c1e5c to your computer and use it in GitHub Desktop.
Modified version of skeleton.js generated by sqlite-to-rest that supports cross-origin requests
'use strict';
//---------//
// Imports //
//---------//
const Koa = require('koa')
, sqliteToRest = require('sqlite-to-rest')
, cors = require('@koa/cors');
//------//
// Init //
//------//
const dbPath = 'databases/test.db'
, getSqliteRouter = sqliteToRest.getSqliteRouter
, PORT = 8085;
//------//
// Main //
//------//
const app = new Koa();
getSqliteRouter({ dbPath })
.then(router => {
app.use(router.routes())
.use(router.allowedMethods())
.use(cors({origin: '*'}))
.listen(PORT);
console.log(`Listening on port: ${PORT}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment