Skip to content

Instantly share code, notes, and snippets.

@tatsuyasusukida
Last active September 8, 2022 01:03
Show Gist options
  • Save tatsuyasusukida/dc5a008f84860ca43bdc82e94eed1366 to your computer and use it in GitHub Desktop.
Save tatsuyasusukida/dc5a008f84860ca43bdc82e94eed1366 to your computer and use it in GitHub Desktop.
🏜 How to avoid "Container terminated due to sandbox error" in Cloud Run
const http = require('http')
main()
function main () {
const server = http.createServer()
server.on('request', (_, res) => {
const content = 'main.js'
res.writeHead(200, {
'Content-Type': 'text/plain',
'Content-Length': content.length,
})
res.write(content)
res.end()
})
server.on('error', (err) => {
console.error(err)
})
server.listen(process.env.PORT)
}
const http = require('http')
if (require.main === module) {
main()
}
function main () {
const server = http.createServer()
server.on('request', (_, res) => {
const content = 'main.js'
res.writeHead(200, {
'Content-Type': 'text/plain',
'Content-Length': content.length,
})
res.write(content)
res.end()
})
server.on('error', (err) => {
console.error(err)
})
server.listen(process.env.PORT)
}
module.exports = main
const http = require('http')
if (require.main === module) {
main()
}
function main () {
const server = http.createServer()
server.on('request', (_, res) => {
const content = 'sub.js'
res.writeHead(200, {
'Content-Type': 'text/plain',
'Content-Length': content.length,
})
res.write(content)
res.end()
})
server.on('error', (err) => {
console.error(err)
})
server.listen(process.env.PORT)
}
module.exports = main
const scriptMain = require('./script-main')
const scriptSub = require('./script-sub')
main()
function main () {
if (process.env.SCRIPT === 'main.js') {
scriptMain()
} else if (process.env.SCRIPT === 'sub.js') {
scriptSub()
} else {
throw new TypeError(`invalid SCRIPT env: ${process.env.SCRIPT}`)
}
}
const http = require('http')
main()
function main () {
const server = http.createServer()
server.on('request', (_, res) => {
const content = 'sub.js'
res.writeHead(200, {
'Content-Type': 'text/plain',
'Content-Length': content.length,
})
res.write(content)
res.end()
})
server.on('error', (err) => {
console.error(err)
})
server.listen(process.env.PORT)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment