Skip to content

Instantly share code, notes, and snippets.

@spddl
Created February 1, 2018 19:45
Show Gist options
  • Save spddl/257ef21ccf52d651a3088b1d08c9f584 to your computer and use it in GitHub Desktop.
Save spddl/257ef21ccf52d651a3088b1d08c9f584 to your computer and use it in GitHub Desktop.
Iris Webspace
package main
import (
"net/url"
"github.com/iris-contrib/middleware/cors"
"github.com/kataras/iris"
"github.com/kataras/iris/core/host"
"github.com/kataras/iris/middleware/logger"
)
// export PATH=$PATH:/usr/local/go/bin
func main() {
app := iris.New()
customLogger := logger.New(logger.Config{
// Status displays status code
Status: true,
// IP displays request's remote address
IP: true,
// Method displays the http method
Method: true,
// Path displays the request path
Path: true,
// Columns: true,
// if !empty then its contents derives from `ctx.Values().Get("logger_message")
// will be added to the logs.
MessageContextKey: "logger_message",
})
app.Use(customLogger)
// enable gzip, optionally:
// if used before the `StaticXXX` handlers then
// the content byte range feature is gone.
// recommend: turn off for large files especially
// when server has low memory,
// turn on for medium-sized files
// or for large-sized files if they are zipped already,
// i.e "zippedDir/file.gz"
app.Use(iris.Gzip)
crs := cors.New(cors.Options{
AllowedOrigins: []string{"*"}, // allows everything, use that to change the hosts.
AllowCredentials: true,
})
app.Use(crs)
// first parameter is the request path
// second is the system directory
app.StaticWeb("/", "/home/pi/node/smarthome/public/")
// app.Run(iris.Addr(":1337"), iris.WithoutServerError(iris.ErrServerClosed))
app.Run(iris.Addr(":1337"), iris.WithConfiguration(iris.Configuration{
DisableVersionChecker: true,
DisableStartupLog: false,
}))
}
const { spawn } = require('child_process')
const ls = spawn('go', ['run', 'iris.go'])
ls.stdout.on('data', (data) => { process.stdout.write(data) })
ls.stderr.on('data', (data) => { process.stdout.write(data) })
ls.on('close', (code) => {
console.log(`child process exited with code ${code}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment