This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const files = require('serve-static') | |
const path = require('path') | |
const cache = require('http-cache-middleware') | |
const serve = files(path.join(__dirname, 'src'), { | |
lastModified: false, | |
setHeaders: (res, path) => { | |
res.setHeader('cache-control', 'public, no-cache, max-age=604800') | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const files = require('serve-static') | |
const path = require('path') | |
// serving "src" as root directory | |
const serve = files(path.join(__dirname, 'src')) | |
const app = require('restana')() | |
app.use(serve) | |
app.start(3000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<header> | |
<title>Super Web!</title> | |
</header> | |
<body> | |
Hello world! | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cache middleware | |
const cache = require('http-cache-middleware')() | |
// enable http cache middleware | |
const gateway = require('fast-gateway') | |
const server = gateway({ | |
middlewares: [cache], | |
routes: [{ | |
prefix: '/tasks', | |
target: 'http://tasks.service' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service.put('/tasks/:id', (req, res) => { | |
// … | |
res.setHeader('x-cache-expire', '*/tasks*') | |
// … | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service.get('/tasks', (req, res) => { | |
// ... | |
res.setHeader('x-cache-timeout', '1 week') | |
// ... | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const middleware = require('http-cache-middleware')() | |
const service = require('restana')() | |
service.use(middleware) | |
service.get('/expensive-route', (req, res) => { | |
const data = // heavy CPU and networking tasks... | |
res.setHeader('x-cache-timeout', '1 week') | |
res.send(data) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gateway = require('fast-gateway') | |
const PORT = process.env.PORT || 8080 | |
gateway({ | |
middlewares: [ | |
require('cors')(), | |
require('helmet')() | |
], | |
routes: [{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const server = require('restana/libs/turbo-http') | |
const service = require('restana')({ | |
server | |
}) | |
service.get('/hi', (req, res) => { | |
res.send('Hello World!') | |
}) | |
service.start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service.use(require('response-time')()) |
NewerOlder